Class: BlueprintComponents::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/blueprint/components.rb

Direct Known Subclasses

Aggregate, Dependency, Parameter, Value

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.blockObject

Returns the value of attribute block.



12
13
14
# File 'lib/blueprint/components.rb', line 12

def block
  @block
end

.item_typeObject

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