Class: ChangeSensitiveHash

Inherits:
Object
  • Object
show all
Defined in:
lib/yodel/models/core/fields/change_sensitive_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(record, field, hash) ⇒ ChangeSensitiveHash

Returns a new instance of ChangeSensitiveHash.



3
4
5
6
7
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 3

def initialize(record, field, hash)
  @record = record
  @field = field
  @hash = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



37
38
39
40
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 37

def method_missing(name, *args, &block)
  notify! if name.to_s.end_with?('!')
  @hash.send(name, *args, &block)
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



2
3
4
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 2

def hash
  @hash
end

Instance Method Details

#[]=(key, value) ⇒ Object



32
33
34
35
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 32

def []=(key, value)
  notify!
  @hash[key] = value
end

#clearObject



27
28
29
30
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 27

def clear
  notify!
  @hash.clear
end

#delete(key) ⇒ Object



22
23
24
25
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 22

def delete(key)
  notify!
  @hash.delete(key)
end

#dupObject

See ChangeSensitiveArray#dup for an explanation of this method



43
44
45
46
47
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 43

def dup
  copy = ChangeSensitiveHash.new(@record.dup, @field.dup, @hash.dup)
  @record.typecast[@field] = copy
  self
end

#inspectObject



9
10
11
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 9

def inspect
  @hash.inspect
end

#merge!(other_hash) ⇒ Object



17
18
19
20
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 17

def merge!(other_hash)
  notify!
  @hash.merge!(other_hash)
end

#to_hashObject



13
14
15
# File 'lib/yodel/models/core/fields/change_sensitive_hash.rb', line 13

def to_hash
  @hash
end