Class: CMS::Type
- Inherits:
-
Object
- Object
- CMS::Type
- Includes:
- ActiveModel::Naming
- Defined in:
- lib/cms/type.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#references ⇒ Object
Returns the value of attribute references.
Instance Method Summary collapse
- #accessible_attributes ⇒ Object
- #attributes_with_index ⇒ Object
- #file_attributes ⇒ Object
-
#initialize(name, attributes, options = {}) ⇒ Type
constructor
A new instance of Type.
- #order_attribute ⇒ Object
- #order_options ⇒ Object
- #orderable? ⇒ Boolean
- #orderable_attributes ⇒ Object
-
#parents ⇒ Object
quacks like a Module.
- #subject ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, attributes, options = {}) ⇒ Type
Returns a new instance of Type.
6 7 8 9 10 11 12 |
# File 'lib/cms/type.rb', line 6 def initialize name, attributes, = {} @name = name @attributes = attributes @options = .symbolize_keys.merge(timestamps: true, indexes: true, model: true) @options.merge!(@options.delete(:options).symbolize_keys) if @options[:options].present? @references = [] end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
2 3 4 |
# File 'lib/cms/type.rb', line 2 def attributes @attributes end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/cms/type.rb', line 2 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
2 3 4 |
# File 'lib/cms/type.rb', line 2 def @options end |
#references ⇒ Object
Returns the value of attribute references.
2 3 4 |
# File 'lib/cms/type.rb', line 2 def references @references end |
Instance Method Details
#accessible_attributes ⇒ Object
14 15 16 |
# File 'lib/cms/type.rb', line 14 def accessible_attributes attributes end |
#attributes_with_index ⇒ Object
18 19 20 |
# File 'lib/cms/type.rb', line 18 def attributes_with_index attributes.select { |a| a.has_index? || (a.reference? && [:indexes]) } end |
#file_attributes ⇒ Object
26 27 28 |
# File 'lib/cms/type.rb', line 26 def file_attributes attributes.select(&:file?) end |
#order_attribute ⇒ Object
34 35 36 |
# File 'lib/cms/type.rb', line 34 def order_attribute orderable_attributes.first end |
#order_options ⇒ Object
38 39 40 |
# File 'lib/cms/type.rb', line 38 def CMS::Template.(order_attribute.) end |
#orderable? ⇒ Boolean
30 31 32 |
# File 'lib/cms/type.rb', line 30 def orderable? !!order_attribute end |
#orderable_attributes ⇒ Object
22 23 24 |
# File 'lib/cms/type.rb', line 22 def orderable_attributes attributes.select(&:orderable?) end |
#parents ⇒ Object
quacks like a Module
4 |
# File 'lib/cms/type.rb', line 4 def parents ; [] end |
#subject ⇒ Object
46 47 48 |
# File 'lib/cms/type.rb', line 46 def subject [:subject] || name end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/cms/type.rb', line 42 def to_s name end |