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.
17 18 19 |
# File 'lib/cistern/singular.rb', line 17 def service @service end |
Class Method Details
.included(klass) ⇒ Object
11 12 13 14 15 |
# File 'lib/cistern/singular.rb', line 11 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
3 4 5 6 7 8 9 |
# File 'lib/cistern/singular.rb', line 3 def self.service_singular(service, klass, name) service.const_get(:Collections).module_eval " def \#{name}(attributes={})\n \#{klass.name}.new(attributes.merge(service: self))\n end\n EOS\nend\n", __FILE__, __LINE__ |
Instance Method Details
#fetch_attributes ⇒ Object
36 37 38 |
# File 'lib/cistern/singular.rb', line 36 def fetch_attributes raise NotImplementedError end |
#initialize(options) ⇒ Object
23 24 25 26 |
# File 'lib/cistern/singular.rb', line 23 def initialize() merge_attributes() reload end |
#inspect ⇒ Object
19 20 21 |
# File 'lib/cistern/singular.rb', line 19 def inspect Cistern.formatter.call(self) end |
#reload ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/cistern/singular.rb', line 28 def reload new_attributes = fetch_attributes if new_attributes merge_attributes(new_attributes) end end |