Class: CMS::Type

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Naming
Defined in:
lib/cms/type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {}
  @name = name
  @attributes = attributes
  @options = 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

#attributesObject

Returns the value of attribute attributes.



2
3
4
# File 'lib/cms/type.rb', line 2

def attributes
  @attributes
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/cms/type.rb', line 2

def name
  @name
end

#optionsObject

Returns the value of attribute options.



2
3
4
# File 'lib/cms/type.rb', line 2

def options
  @options
end

#referencesObject

Returns the value of attribute references.



2
3
4
# File 'lib/cms/type.rb', line 2

def references
  @references
end

Instance Method Details

#accessible_attributesObject



14
15
16
# File 'lib/cms/type.rb', line 14

def accessible_attributes
  attributes
end

#attributes_with_indexObject



18
19
20
# File 'lib/cms/type.rb', line 18

def attributes_with_index
  attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
end

#file_attributesObject



26
27
28
# File 'lib/cms/type.rb', line 26

def file_attributes
  attributes.select(&:file?)
end

#order_attributeObject



34
35
36
# File 'lib/cms/type.rb', line 34

def order_attribute
  orderable_attributes.first
end

#order_optionsObject



38
39
40
# File 'lib/cms/type.rb', line 38

def order_options
  CMS::Template.inject_options(order_attribute.options)
end

#orderable?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cms/type.rb', line 30

def orderable?
  !!order_attribute
end

#orderable_attributesObject



22
23
24
# File 'lib/cms/type.rb', line 22

def orderable_attributes
  attributes.select(&:orderable?)
end

#parentsObject

quacks like a Module



4
# File 'lib/cms/type.rb', line 4

def parents ; [] end

#subjectObject



46
47
48
# File 'lib/cms/type.rb', line 46

def subject
  options[:subject] || name
end

#to_sObject



42
43
44
# File 'lib/cms/type.rb', line 42

def to_s
  name
end