Class: DeltaCore::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/delta_core/snapshot.rb

Constant Summary collapse

FORMAT_VERSION =
1
VERSION_KEY =
"_v"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw = nil) ⇒ Snapshot

Returns a new instance of Snapshot.



10
11
12
# File 'lib/delta_core/snapshot.rb', line 10

def initialize(raw = nil)
  @state = parse(raw)
end

Instance Attribute Details

#state ⇒ Object (readonly)

Returns the value of attribute state.



8
9
10
# File 'lib/delta_core/snapshot.rb', line 8

def state
  @state
end

Instance Method Details

#empty? ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/delta_core/snapshot.rb', line 14

def empty?
  @state.empty?
end

#serialize(current_state) ⇒ Object



18
19
20
21
22
# File 'lib/delta_core/snapshot.rb', line 18

def serialize(current_state)
  payload = { VERSION_KEY => FORMAT_VERSION }
  payload.merge!(stringify_keys(current_state))
  JSON.generate(payload)
end