Class: Adminable::Resource

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/adminable/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • name (String)

    resource name, usually same as the model name



8
9
10
11
# File 'lib/adminable/resource.rb', line 8

def initialize(name)
  @name = name
  @model = name.classify.constantize
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



5
6
7
# File 'lib/adminable/resource.rb', line 5

def fields
  @fields
end

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/adminable/resource.rb', line 5

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/adminable/resource.rb', line 5

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
# File 'lib/adminable/resource.rb', line 18

def <=>(other)
  other.is_a?(Adminable::Resource) && name <=> other.name
end

#routeString

Returns for route helper name.

Returns:

  • (String)

    for route helper name



14
15
16
# File 'lib/adminable/resource.rb', line 14

def route
  @route ||= @model.name.underscore.pluralize.tr('/', '_')
end