Class: Para::ComponentsConfiguration::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/para/components_configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, &block) ⇒ Section

Returns a new instance of Section.



112
113
114
115
# File 'lib/para/components_configuration.rb', line 112

def initialize(identifier, &block)
  self.identifier = identifier.to_s
  instance_eval(&block)
end

Instance Attribute Details

#identifierObject

Returns the value of attribute identifier.



110
111
112
# File 'lib/para/components_configuration.rb', line 110

def identifier
  @identifier
end

#modelObject

Returns the value of attribute model.



110
111
112
# File 'lib/para/components_configuration.rb', line 110

def model
  @model
end

Instance Method Details

#component(*args) ⇒ Object



117
118
119
# File 'lib/para/components_configuration.rb', line 117

def component(*args)
  components << Component.new(*args)
end

#componentsObject



121
122
123
# File 'lib/para/components_configuration.rb', line 121

def components
  @components ||= []
end

#refresh(attributes = {}) ⇒ Object



125
126
127
128
129
130
131
132
133
# File 'lib/para/components_configuration.rb', line 125

def refresh(attributes = {})
  self.model = ComponentSection.where(identifier: identifier).first_or_initialize
  model.assign_attributes(attributes)
  model.save!

  components.each_with_index do |component, index|
    component.refresh(component_section: model, position: index)
  end
end