module Gearbox::SubjectMethods::InstanceMethods
Attributes
base_uri[RW]
id[W]
id_method[RW]
Gives us the ability to derive an id from other sources or patterns. Based on the identifier patterns: patterns.dataincubator.org/book/
subject_decorator[RW]
Allows patterns to be used to define the subject.
Public Class Methods
new(opts={})
click to toggle source
Calls superclass method
# File lib/gearbox/mixins/subject_methods.rb, line 31 def initialize(opts={}) super set_attributes_from_configuration_or_opts(opts, :base_uri, :id_method, :id, :subject_decorator) end
Public Instance Methods
id()
click to toggle source
# File lib/gearbox/mixins/subject_methods.rb, line 36 def id return @id if @id send(id_method) end
subject()
click to toggle source
subject_decorator
-> internal method -> subject subject_decorator
-> lambda -> subject (base_uri
+ (id_method
-> id)) -> subject There are several ways to create the subject. First, the subject_decorator
will use whatever instance values that are set to build a pattern. Second, the base_uri
and id are combined to create the subject.
Note, the id can be set directly, or set with the id_method
, so UUID, or an external source, or a slug generating method can be used to generate an id.
# File lib/gearbox/mixins/subject_methods.rb, line 58 def subject if subject_decorator derive_subject_from_decorator else derive_subject_from_base_uri_and_id end end
Private Instance Methods
derive_subject_from_base_uri_and_id()
click to toggle source
# File lib/gearbox/mixins/subject_methods.rb, line 73 def derive_subject_from_base_uri_and_id File.join(base_uri.to_s, id.to_s) end
derive_subject_from_decorator()
click to toggle source
# File lib/gearbox/mixins/subject_methods.rb, line 68 def derive_subject_from_decorator subject_decorator.respond_to?(:call) ? subject_decorator.call(self) : self.send(subject_decorator) end
set_attributes_from_configuration_or_opts(opts, *attributes)
click to toggle source
# File lib/gearbox/mixins/subject_methods.rb, line 77 def set_attributes_from_configuration_or_opts(opts, *attributes) attributes.each do |attribute| variable_name = "@#{attribute}" instance_variable_set(variable_name, self.class.send(attribute)) if self.class.respond_to?(attribute) instance_variable_set(variable_name, opts[attribute]) if opts.has_key?(attribute) end end