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.



252
253
254
255
# File 'lib/para/components_configuration.rb', line 252

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

Instance Attribute Details

#identifierObject

Returns the value of attribute identifier.



250
251
252
# File 'lib/para/components_configuration.rb', line 250

def identifier
  @identifier
end

#modelObject

Returns the value of attribute model.



250
251
252
# File 'lib/para/components_configuration.rb', line 250

def model
  @model
end

Instance Method Details

#component(*args, **options, &block) ⇒ Object



257
258
259
# File 'lib/para/components_configuration.rb', line 257

def component(*args, **options, &block)
  components << Component.new(*args, **options, &block)
end

#componentsObject



261
262
263
# File 'lib/para/components_configuration.rb', line 261

def components
  @components ||= []
end

#refresh(attributes = {}) ⇒ Object



265
266
267
268
269
270
271
272
273
# File 'lib/para/components_configuration.rb', line 265

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