Class: Locomotive::CurrentSiteMetafieldsHelper::SchemaGroup

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/locomotive/current_site_metafields_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(site, attributes) ⇒ SchemaGroup

Returns a new instance of SchemaGroup.



12
13
14
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 12

def initialize(site, attributes)
  @site, @attributes = site, attributes
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 40

def method_missing(name, *args, &block)
  if field = _fields.find { |f| f.name == name.to_s }
    field.value
  else
    super
  end
end

Instance Method Details

#_fieldsObject



34
35
36
37
38
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 34

def _fields
  @fields ||= @attributes['fields'].map do |f|
    SchemaField.new(@site, _name, f)
  end.sort_by(&:position)
end

#_labelObject



26
27
28
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 26

def _label
  _t(@attributes['label'] || @attributes['name'].humanize)
end

#_nameObject Also known as: dom_id



16
17
18
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 16

def _name
  @attributes['name'].downcase.underscore.gsub(' ', '_')
end

#_positionObject



30
31
32
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 30

def _position
  @attributes['position']
end

#model_nameObject



22
23
24
# File 'app/helpers/locomotive/current_site_metafields_helper.rb', line 22

def model_name
  ActiveModel::Name.new(self, nil, _name)
end