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.



114
115
116
117
# File 'lib/para/components_configuration.rb', line 114

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

Instance Attribute Details

#identifierObject

Returns the value of attribute identifier.



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

def identifier
  @identifier
end

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

Instance Method Details

#component(*args) ⇒ Object



119
120
121
# File 'lib/para/components_configuration.rb', line 119

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

#componentsObject



123
124
125
# File 'lib/para/components_configuration.rb', line 123

def components
  @components ||= []
end

#refresh(attributes = {}) ⇒ Object



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

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