Class: Modular::Components::Container
- Inherits:
-
Base
- Object
- Helpers::AbstractModel
- Base
- Modular::Components::Container
- Defined in:
- lib/modular/components/container.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
Attributes inherited from Base
Instance Method Summary collapse
- #add(type, args = {}, &block) ⇒ Object
-
#initialize(attributes = {}) ⇒ Container
constructor
A new instance of Container.
Methods inherited from Base
Methods included from Rendering
#action_name, #controller_path, #execute, #flash, #params, #protect_against_forgery?, #render
Methods inherited from Helpers::AbstractModel
attr_accessor, attr_accessor_with_default, attr_reader, attr_reader_with_default, attr_writer, #persisted?, #to_json
Constructor Details
#initialize(attributes = {}) ⇒ Container
Returns a new instance of Container.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/modular/components/container.rb', line 6 def initialize(attributes = {}) @attributes = ActiveSupport::HashWithIndifferentAccess.new(:components => []) attributes = attributes.with_indifferent_access attributes["components"] ||= [] attributes["components"].each do |value| if value.is_a? Modular::Components::Base @attributes[:components].push value else @attributes[:components].push(Modular.from_json(value)) rescue '' end end super(attributes.except("components")) end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
4 5 6 |
# File 'lib/modular/components/container.rb', line 4 def components @components end |
Instance Method Details
#add(type, args = {}, &block) ⇒ Object
22 23 24 25 26 |
# File 'lib/modular/components/container.rb', line 22 def add(type, args = {}, &block) cont = Modular.create(type, args) cont.instance_eval &block if block_given? components.push cont end |