Class: RgGen::Builder::ItemStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rggen/builder/item_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, factory) ⇒ ItemStore



4
5
6
7
8
9
10
# File 'lib/rggen/builder/item_store.rb', line 4

def initialize(base, factory)
  @base                 = base
  @factory              = factory
  @simple_item_entries  = {}
  @list_item_entries    = {}
  @enabled_entries      = []
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



12
13
14
# File 'lib/rggen/builder/item_store.rb', line 12

def base
  @base
end

#factoryObject (readonly)

Returns the value of attribute factory.



13
14
15
# File 'lib/rggen/builder/item_store.rb', line 13

def factory
  @factory
end

Instance Method Details

#build_factoriesObject



39
40
41
42
43
44
45
# File 'lib/rggen/builder/item_store.rb', line 39

def build_factories
  @enabled_entries.each_with_object({}) do |entry_name, factories|
    factories[entry_name] = (
      @simple_item_entries[entry_name] || @list_item_entries[entry_name]
    ).build_factory
  end
end

#define_list_item(context, list_name, item_name = nil, &body) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rggen/builder/item_store.rb', line 19

def define_list_item(context, list_name, item_name = nil, &body)
  if item_name.nil?
    create_item_entry(:list, list_name, context, body)
  else
    define_list_item_class(list_name, item_name, context, body)
  end
end

#define_simple_item(context, item_name, &body) ⇒ Object



15
16
17
# File 'lib/rggen/builder/item_store.rb', line 15

def define_simple_item(context, item_name, &body)
  create_item_entry(:simple, item_name, context, body)
end

#enable(*args) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rggen/builder/item_store.rb', line 27

def enable(*args)
  case args.size
  when 1
    enable_item_entries(args[0])
  when 2
    enable_list_item(args[0], args[1])
  else
    message = "wrong number of arguments (#{args.size} for 1..2)"
    fail ArgumentError, message
  end
end