class JIRA::BaseFactory
This is the base class for all the JIRA
resource factory instances.
Attributes
client[R]
Public Class Methods
delegate_to_target_class(*method_names)
click to toggle source
# File lib/jira/base_factory.rb, line 28 def self.delegate_to_target_class(*method_names) method_names.each do |method_name| define_method method_name do |*args| target_class.send(method_name, @client, *args) end end end
new(client)
click to toggle source
# File lib/jira/base_factory.rb, line 6 def initialize(client) @client = client end
Public Instance Methods
build(attrs = {})
click to toggle source
This method needs special handling as it has a default argument value
# File lib/jira/base_factory.rb, line 42 def build(attrs = {}) target_class.build(@client, attrs) end
target_class()
click to toggle source
Return the name of the class which this factory generates, i.e. JIRA::Resource::FooFactory creates JIRA::Resource::Foo instances.
# File lib/jira/base_factory.rb, line 12 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 components. 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