Class: RgGen::Builder::ItemStore
- Inherits:
-
Object
- Object
- RgGen::Builder::ItemStore
- Defined in:
- lib/rggen/builder/item_store.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#factory ⇒ Object
readonly
Returns the value of attribute factory.
Instance Method Summary collapse
- #build_factories ⇒ Object
- #define_list_item(context, list_name, item_name = nil, &body) ⇒ Object
- #define_simple_item(context, item_name, &body) ⇒ Object
- #enable(*args) ⇒ Object
-
#initialize(base, factory) ⇒ ItemStore
constructor
A new instance of ItemStore.
Constructor Details
#initialize(base, factory) ⇒ ItemStore
Returns a new instance of 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
#base ⇒ Object (readonly)
Returns the value of attribute base.
12 13 14 |
# File 'lib/rggen/builder/item_store.rb', line 12 def base @base end |
#factory ⇒ Object (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_factories ⇒ Object
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 = "wrong number of arguments (#{args.size} for 1..2)" raise ArgumentError, end end |