Class: Mozaic::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/mozaic/component.rb,
lib/mozaic/component/define.rb

Defined Under Namespace

Modules: Define

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}, &block) ⇒ Component



9
10
11
12
13
14
15
# File 'lib/mozaic/component.rb', line 9

def initialize name, options = {}, &block
    self.name = name.to_sym
    self.block = block if block_given?
    self.defaults = options
    self.class.instances = [] if @@instances.nil?
    self.class.instances << self
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



6
7
8
# File 'lib/mozaic/component.rb', line 6

def block
  @block
end

#defaultsObject

Returns the value of attribute defaults.



7
8
9
# File 'lib/mozaic/component.rb', line 7

def defaults
  @defaults
end

#nameObject

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 options options = {}
    @defaults.merge options
end

#render(options = {}) ⇒ Object



21
22
23
# File 'lib/mozaic/component.rb', line 21

def render options = {}
    self.block.call(self.options(options)) unless self.block.nil?
end