Module: Cistern::Singular
- Defined in:
- lib/cistern/singular.rb
Instance Attribute Summary collapse
-
#service ⇒ Object
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#service ⇒ Object
Returns the value of attribute service.
16 17 18 |
# File 'lib/cistern/singular.rb', line 16 def service @service end |
Class Method Details
.included(klass) ⇒ Object
10 11 12 13 14 |
# File 'lib/cistern/singular.rb', line 10 def self.included(klass) klass.send(:extend, Cistern::Attributes::ClassMethods) klass.send(:include, Cistern::Attributes::InstanceMethods) klass.send(:extend, Cistern::Model::ClassMethods) end |
.service_singular(service, klass, name) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/cistern/singular.rb', line 2 def self.service_singular(service, klass, name) service.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__ def #{name}(attributes={}) #{klass.name}.new(attributes.merge(service: self)) end EOS end |
Instance Method Details
#fetch_attributes ⇒ Object
33 34 35 |
# File 'lib/cistern/singular.rb', line 33 def fetch_attributes fail NotImplementedError end |
#initialize(options) ⇒ Object
22 23 24 25 |
# File 'lib/cistern/singular.rb', line 22 def initialize() merge_attributes() reload end |
#inspect ⇒ Object
18 19 20 |
# File 'lib/cistern/singular.rb', line 18 def inspect Cistern.formatter.call(self) end |
#reload ⇒ Object
27 28 29 30 31 |
# File 'lib/cistern/singular.rb', line 27 def reload new_attributes = fetch_attributes merge_attributes(new_attributes) if new_attributes end |