Module: Modis::Persistence::ClassMethods

Defined in:
lib/modis/persistence.rb

Instance Method Summary collapse

Instance Method Details

#absolute_namespaceObject



42
43
44
45
# File 'lib/modis/persistence.rb', line 42

def absolute_namespace
  parts = [Modis.config.namespace, namespace]
  @absolute_namespace = parts.compact.join(':')
end

#bootstrap_sti(parent, child) ⇒ Object

:nodoc:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/modis/persistence.rb', line 9

def bootstrap_sti(parent, child)
  child.instance_eval do
  parent.instance_eval do
    class << self
        attr_accessor :sti_parent
      end
      attribute :type, :string
    end

    class << self
      delegate :attributes, to: :sti_parent
    end

    @sti_child = true
    @sti_parent = parent
  end
end

#create(attrs) ⇒ Object



51
52
53
54
55
# File 'lib/modis/persistence.rb', line 51

def create(attrs)
    model = new(attrs)
    model.save
    model
end

#create!(attrs) ⇒ Object



57
58
59
60
61
# File 'lib/modis/persistence.rb', line 57

def create!(attrs)
  model = new(attrs)
  model.save!
  model
end

#key_for(id) ⇒ Object



47
48
49
# File 'lib/modis/persistence.rb', line 47

def key_for(id)
  "#{absolute_namespace}:#{id}"
end

#namespaceObject



32
33
34
35
36
# File 'lib/modis/persistence.rb', line 32

def namespace
  return sti_parent.namespace if sti_child?
  return @namespace if @namespace
  @namespace = name.split('::').map(&:underscore).join(':')
end

#namespace=(value) ⇒ Object



38
39
40
# File 'lib/modis/persistence.rb', line 38

def namespace=(value)
  @namespace = value
end

#sti_child?Boolean

:nodoc:

Returns:

  • (Boolean)


28
29
30
# File 'lib/modis/persistence.rb', line 28

def sti_child?
  @sti_child == true
end