Class: BlueprintComponents::Component
- Inherits:
-
Object
- Object
- BlueprintComponents::Component
- Defined in:
- lib/blueprint/components.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.block ⇒ Object
Returns the value of attribute block.
-
.item_type ⇒ Object
Returns the value of attribute item_type.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes(*args) ⇒ Object
-
#initialize(*args) ⇒ Component
constructor
A new instance of Component.
- #remove_attribute(attr) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Component
Returns a new instance of Component.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/blueprint/components.rb', line 27 def initialize(*args) opts = args.last.is_a?(Hash) ? args.pop : {} if opts opts.clone.keys.each do |k| if BLUEPRINT_TRANSLATIONS.key?(k) opts[BLUEPRINT_TRANSLATIONS[k]] = opts.delete(k) end end end @def = { :item_type => self.class.item_type }.merge(opts) if self.class.block @def.merge!(self.class.block.call(self, args, opts)) end end |
Class Attribute Details
.block ⇒ Object
Returns the value of attribute block.
12 13 14 |
# File 'lib/blueprint/components.rb', line 12 def block @block end |
.item_type ⇒ Object
Returns the value of attribute item_type.
11 12 13 |
# File 'lib/blueprint/components.rb', line 11 def item_type @item_type end |
Class Method Details
.creates(*args, &block) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/blueprint/components.rb', line 15 def self.creates(*args, &block) self.item_type = args.pop if block_given? self.block = block end end |
Instance Method Details
#attributes(*args) ⇒ Object
22 23 24 25 |
# File 'lib/blueprint/components.rb', line 22 def attributes(*args) opts = args.last.is_a?(Hash) ? args.pop : {} @def.merge!(:attributes => opts) end |
#remove_attribute(attr) ⇒ Object
44 45 46 |
# File 'lib/blueprint/components.rb', line 44 def remove_attribute(attr) @def.delete(attr) end |