Class: Jira::Resource::BaseFactory
- Inherits:
-
Object
- Object
- Jira::Resource::BaseFactory
- Defined in:
- lib/jira/resource/base_factory.rb
Overview
This is the base class for all the Jira resource factory instances.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #all ⇒ Object
- #build(attrs = {}) ⇒ Object
- #find(key) ⇒ Object
-
#initialize(client) ⇒ BaseFactory
constructor
A new instance of BaseFactory.
-
#target_class ⇒ Object
Return the name of the class which this factory generates, i.e.
Constructor Details
#initialize(client) ⇒ BaseFactory
Returns a new instance of BaseFactory.
9 10 11 |
# File 'lib/jira/resource/base_factory.rb', line 9 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
7 8 9 |
# File 'lib/jira/resource/base_factory.rb', line 7 def client @client end |
Instance Method Details
#all ⇒ Object
31 32 33 |
# File 'lib/jira/resource/base_factory.rb', line 31 def all target_class.all(@client) end |
#build(attrs = {}) ⇒ Object
39 40 41 |
# File 'lib/jira/resource/base_factory.rb', line 39 def build(attrs={}) target_class.build(@client, attrs) end |
#find(key) ⇒ Object
35 36 37 |
# File 'lib/jira/resource/base_factory.rb', line 35 def find(key) target_class.find(@client, key) end |
#target_class ⇒ Object
Return the name of the class which this factory generates, i.e. Jira::Resource::FooFactory creates Jira::Resource::Foo instances.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jira/resource/base_factory.rb', line 15 def target_class # Need to do a little bit of work here as Module.const_get doesn't work # with nested class names, i.e. Jira::Resource::Foo. # # So create a method chain from the class componenets. This code will # unroll to: # Module.const_get('Jira').const_get('Resource').const_get('Foo') # target_class_name = self.class.name.sub(/Factory$/, '') class_components = target_class_name.split('::') class_components.inject(Module) do |mod, const_name| mod.const_get(const_name) end end |