Module: Locabulary::Item
- Defined in:
- lib/locabulary/item.rb
Overview
A container of builder methods for items
Class Method Summary collapse
-
.build(attributes = {}) ⇒ Locabulary::Item
A Factory method that is responsible for building the appropriate object given a :predicate_name and additional attributes.
-
.builder_for(options = {}) ⇒ #call
deprecated
Deprecated.
0.6.0 Prefer instead class_to_instantiate; This will be removed in 0.7.0.
-
.class_to_instantiate(options = {}) ⇒ Locabulary::Items::Base
Responsible for finding the appropriate class that will be instantiated.
Class Method Details
.build(attributes = {}) ⇒ Locabulary::Item
A Factory method that is responsible for building the appropriate object given a :predicate_name and additional attributes.
16 17 18 19 |
# File 'lib/locabulary/item.rb', line 16 def self.build(attributes = {}) predicate_name = attributes.fetch(:predicate_name) { attributes.fetch('predicate_name') } class_to_instantiate(predicate_name: predicate_name).new(attributes) end |
.builder_for(options = {}) ⇒ #call
Deprecated.
0.6.0 Prefer instead class_to_instantiate; This will be removed in 0.7.0.
Responsible for finding the appropriate Factory method for building a Locabulary::Item
30 31 32 |
# File 'lib/locabulary/item.rb', line 30 def self.builder_for( = {}) class_to_instantiate().method(:new) end |
.class_to_instantiate(options = {}) ⇒ Locabulary::Items::Base
Responsible for finding the appropriate class that will be instantiated
42 43 44 45 46 47 48 49 50 |
# File 'lib/locabulary/item.rb', line 42 def self.class_to_instantiate( = {}) predicate_name = .fetch(:predicate_name) possible_class_name_for_predicate_name = predicate_name.singularize.classify begin "Locabulary::Items::#{possible_class_name_for_predicate_name}".constantize rescue NameError Items::Base end end |