Class: SkyDB::Property
- Inherits:
-
Object
- Object
- SkyDB::Property
- Defined in:
- lib/skydb/property.rb
Instance Attribute Summary collapse
-
#data_type ⇒ Object
The property’s data type.
-
#id ⇒ Object
The property identifier.
-
#name ⇒ Object
The name of the property.
-
#transient ⇒ Object
A flag stating if the value of the property only exists for a single moment.
Instance Method Summary collapse
- #as_json(*a) ⇒ Object
-
#from_hash(hash, *a) ⇒ Object
Decodes a hash into a property.
-
#initialize(options = {}) ⇒ Property
constructor
Initializes the property.
-
#to_hash(*a) ⇒ Object
Encodes the property into a hash.
- #to_json(*a) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Property
Initializes the property.
10 11 12 13 14 15 |
# File 'lib/skydb/property.rb', line 10 def initialize(={}) self.id = [:id].to_i self.name = [:name] self.transient = [:transient] || false self.data_type = [:data_type] || "string" end |
Instance Attribute Details
#data_type ⇒ Object
The property’s data type.
34 35 36 |
# File 'lib/skydb/property.rb', line 34 def data_type @data_type end |
#id ⇒ Object
The property identifier.
25 26 27 |
# File 'lib/skydb/property.rb', line 25 def id @id end |
#name ⇒ Object
The name of the property.
28 29 30 |
# File 'lib/skydb/property.rb', line 28 def name @name end |
#transient ⇒ Object
A flag stating if the value of the property only exists for a single moment.
31 32 33 |
# File 'lib/skydb/property.rb', line 31 def transient @transient end |
Instance Method Details
#as_json(*a) ⇒ Object
67 |
# File 'lib/skydb/property.rb', line 67 def as_json(*a); return to_hash(*a); end |
#from_hash(hash, *a) ⇒ Object
Decodes a hash into a property.
59 60 61 62 63 64 65 |
# File 'lib/skydb/property.rb', line 59 def from_hash(hash, *a) self.id = !hash.nil? ? hash['id'].to_i : 0 self.name = !hash.nil? ? hash['name'] : '' self.transient = !hash.nil? ? hash['transient'] : false self.data_type = !hash.nil? ? hash['dataType'] : '' return self end |
#to_hash(*a) ⇒ Object
Encodes the property into a hash.
48 49 50 51 52 53 54 55 56 |
# File 'lib/skydb/property.rb', line 48 def to_hash(*a) hash = { 'name' => name, 'transient' => transient, 'dataType' => data_type, } hash['id'] = id if id < 0 || id > 0 return hash end |
#to_json(*a) ⇒ Object
68 |
# File 'lib/skydb/property.rb', line 68 def to_json(*a); return as_json(*a).to_json; end |