Class: Sprig::Dependency

Inherits:
Object
  • Object
show all
Defined in:
lib/sprig/dependency.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, sprig_id) ⇒ Dependency

Returns a new instance of Dependency.



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

def initialize(klass, sprig_id)
  @klass = klass
  @sprig_id = sprig_id
  @id = SecureRandom.uuid

  self.class.collection.set(klass, sprig_id, self)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/sprig/dependency.rb', line 3

def id
  @id
end

Class Method Details

.for(klass, sprig_id) ⇒ Object



5
6
7
8
9
10
# File 'lib/sprig/dependency.rb', line 5

def self.for(klass, sprig_id)
  klass = to_klass(klass)
  sprig_id = sprig_id.to_s

  collection.get(klass, sprig_id) || new(klass, sprig_id)
end

Instance Method Details

#sprig_record_referenceObject



20
21
22
# File 'lib/sprig/dependency.rb', line 20

def sprig_record_reference
  "sprig_record(#{klass}, #{sprig_id})"
end