Module: Modis::Persistence::ClassMethods
- Defined in:
- lib/modis/persistence.rb
Instance Attribute Summary collapse
Instance Method Summary collapse
- #absolute_namespace ⇒ Object
-
#bootstrap_sti(parent, child) ⇒ Object
:nodoc:.
- #coerce_from_persistence(value) ⇒ Object
- #create(attrs) ⇒ Object
- #create!(attrs) ⇒ Object
- #key_for(id) ⇒ Object
-
#sti_child? ⇒ Boolean
:nodoc:.
Instance Attribute Details
#namespace ⇒ Object
36 37 38 39 40 |
# File 'lib/modis/persistence.rb', line 36 def namespace return sti_parent.namespace if sti_child? return @namespace if @namespace @namespace = name.split('::').map(&:underscore).join(':') end |
Instance Method Details
#absolute_namespace ⇒ Object
44 45 46 47 |
# File 'lib/modis/persistence.rb', line 44 def absolute_namespace parts = [Modis.config.namespace, namespace] @absolute_namespace = parts.compact.join(':') end |
#bootstrap_sti(parent, child) ⇒ Object
:nodoc:
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/modis/persistence.rb', line 13 def bootstrap_sti(parent, child) child.instance_eval do parent.instance_eval do class << self attr_accessor :sti_parent end attribute :type, :string unless attributes.key?('type') end class << self delegate :attributes, :indexed_attributes, to: :sti_parent end @sti_child = true @sti_parent = parent end end |
#coerce_from_persistence(value) ⇒ Object
65 66 67 |
# File 'lib/modis/persistence.rb', line 65 def coerce_from_persistence(value) YAML.load(value) end |
#create(attrs) ⇒ Object
53 54 55 56 57 |
# File 'lib/modis/persistence.rb', line 53 def create(attrs) model = new(attrs) model.save model end |
#create!(attrs) ⇒ Object
59 60 61 62 63 |
# File 'lib/modis/persistence.rb', line 59 def create!(attrs) model = new(attrs) model.save! model end |
#key_for(id) ⇒ Object
49 50 51 |
# File 'lib/modis/persistence.rb', line 49 def key_for(id) "#{absolute_namespace}:#{id}" end |
#sti_child? ⇒ Boolean
:nodoc:
32 33 34 |
# File 'lib/modis/persistence.rb', line 32 def sti_child? @sti_child == true end |