Class: Mozaic::Component
- Inherits:
-
Object
- Object
- Mozaic::Component
- Defined in:
- lib/mozaic/component.rb,
lib/mozaic/component/define.rb
Defined Under Namespace
Modules: Define
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, options = {}, &block) ⇒ Component
constructor
A new instance of Component.
- #options(options = {}) ⇒ Object
- #render(options = {}) ⇒ Object
Constructor Details
#initialize(name, options = {}, &block) ⇒ Component
9 10 11 12 13 14 15 |
# File 'lib/mozaic/component.rb', line 9 def initialize name, = {}, &block self.name = name.to_sym self.block = block if block_given? self.defaults = self.class.instances = [] if @@instances.nil? self.class.instances << self end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
6 7 8 |
# File 'lib/mozaic/component.rb', line 6 def block @block end |
#defaults ⇒ Object
Returns the value of attribute defaults.
7 8 9 |
# File 'lib/mozaic/component.rb', line 7 def defaults @defaults end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/mozaic/component.rb', line 5 def name @name end |
Class Method Details
.find_by_name(name) ⇒ Object
25 26 27 28 |
# File 'lib/mozaic/component.rb', line 25 def self.find_by_name name return [] if self.instances.nil? self.instances.select { |component| component.name == name.to_sym } end |
Instance Method Details
#options(options = {}) ⇒ Object
17 18 19 |
# File 'lib/mozaic/component.rb', line 17 def = {} @defaults.merge end |
#render(options = {}) ⇒ Object
21 22 23 |
# File 'lib/mozaic/component.rb', line 21 def render = {} self.block.call(self.()) unless self.block.nil? end |