Module: Cistern::Singular

Includes:
Model
Defined in:
lib/cistern/singular.rb

Instance Attribute Summary

Attributes included from Model

#cistern

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

#==, #cistern_class, cistern_model, #hash, #initialize, #inspect, #save, #service, #service=, #service_class, #update, #wait_for, #wait_for!

Methods included from HashSupport

#hash_except, #hash_except!, #hash_slice, #hash_stringify_keys

Methods included from Attributes::InstanceMethods

#attributes, #attributes=, #changed, #dirty?, #dirty_attributes, #dirty_request_attributes, #dump, #dup, #identity, #identity=, #merge_attributes, #new_record?, #read_attribute, #request_attributes, #requires, #requires_one, #stage_attributes, #write_attribute

Class Method Details

.cistern_singular(cistern, klass, name) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/cistern/singular.rb', line 4

def self.cistern_singular(cistern, klass, name)
  cistern.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
    def #{name}(attributes={})
      #{klass.name}.new(attributes.merge(cistern: self))
    end
  EOS
end

.included(klass) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/cistern/singular.rb', line 12

def self.included(klass)
  super

  klass.send(:extend, Cistern::Attributes::ClassMethods)
  klass.send(:include, Cistern::Attributes::InstanceMethods)
  klass.send(:extend, Cistern::Model::ClassMethods)
end

Instance Method Details

#collectionObject



20
21
22
# File 'lib/cistern/singular.rb', line 20

def collection
  self
end

#getObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/cistern/singular.rb', line 24

def get
  raise NotImplementedError
end

#reloadObject Also known as: load



28
29
30
31
# File 'lib/cistern/singular.rb', line 28

def reload
  get
  self
end