Module: ProjectStore::Entity::Builder

Included in:
Base
Defined in:
lib/project_store/entity/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#decoratorsObject

Returns the value of attribute decorators.



6
7
8
# File 'lib/project_store/entity/builder.rb', line 6

def decorators
  @decorators
end

Instance Method Details

#add_decorators(entity) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/project_store/entity/builder.rb', line 20

def add_decorators(entity)
  [:_default, entity.type].each do |decorator_name|
    case decorators[decorator_name]
      when Array
        decorators[decorator_name]
      when NilClass
        []
      else
        [decorators[decorator_name]]
    end .each do |decorator|
      entity.extend decorator
      entity.mandatory_properties.concat decorator.mandatory_properties if decorator.respond_to? :mandatory_properties
      ProjectStore.logger.debug "Decorated entity '#{entity.name}' with '#{decorator}'"
    end
  end
end

#setup_entity!(entity_name, entity = {}, entity_type = nil) {|entity| ... } ⇒ Object

Yields:

  • (entity)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/project_store/entity/builder.rb', line 8

def setup_entity!(entity_name, entity = {}, entity_type = nil)
  entity.extend ProjectStore::Entity::Base
  entity.name = entity_name
  entity.type = entity_type unless entity_type.nil?
  entity.basic_checks
  ProjectStore.logger.info "New entity '#{entity.name}' of type '#{entity.type}'."
  # Adds extra decorator
  add_decorators entity
  yield entity if block_given?
  entity
end