Class: Toaster::KeyValuePair
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Toaster::KeyValuePair
show all
- Defined in:
- lib/toaster/model/key_value_pair.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of KeyValuePair.
13
14
15
16
17
18
19
|
# File 'lib/toaster/model/key_value_pair.rb', line 13
def initialize(hash)
if !hash[:type]
type = IgnoreProperty.to_s
end
super(hash)
@attributes_cache = {} if !@attributes_cache end
|
Class Method Details
.flat_attributes_from_hash(hash, clazz = KeyValuePair) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/toaster/model/key_value_pair.rb', line 41
def self.flat_attributes_from_hash(hash, clazz=KeyValuePair)
result = []
return result if !hash
SystemState.get_flat_attributes(hash).each do |key,value|
result << clazz.new(
:key => key,
:value => value
)
end
return result
end
|
.from_hash(hash, clazz = KeyValuePair) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/toaster/model/key_value_pair.rb', line 29
def self.from_hash(hash, clazz=KeyValuePair)
result = []
return result if !hash
hash.each { |key,value|
result << clazz.new(
:key => key,
:value => value
)
}
return result
end
|
.get_as_hash(list) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/toaster/model/key_value_pair.rb', line 21
def self.get_as_hash(list)
attrs = {}
list.each do |a|
attrs[a.key] = a.value
end
return attrs
end
|
Instance Method Details
#hash ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/toaster/model/key_value_pair.rb', line 57
def hash
begin
return id if id
rescue
end
h = 0
h += key.hash rescue 0
h += value.hash rescue 0
h += type.hash rescue 0
h += data_type.hash rescue 0
return h
end
|
#to_s ⇒ Object
53
54
55
|
# File 'lib/toaster/model/key_value_pair.rb', line 53
def to_s
return "#{self.class}(#{key}=#{value})"
end
|