Class: UnifiedDB::Result::Base
- Inherits:
-
Object
- Object
- UnifiedDB::Result::Base
- Defined in:
- lib/unified_db/result/base.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params) ⇒ Base
constructor
A new instance of Base.
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 |
# File 'lib/unified_db/result/base.rb', line 7 def initialize(params) allowed_keys.each do |key| instance_variable_set("@#{key}", params[key]) end end |
Class Method Details
.allowed_keys ⇒ Object
5 |
# File 'lib/unified_db/result/base.rb', line 5 def self.allowed_keys; []; end |
Instance Method Details
#to_h ⇒ Object
13 14 15 |
# File 'lib/unified_db/result/base.rb', line 13 def to_h allowed_keys.inject({}) { |hash, key| hash[key] = instance_variable_get("@#{key}"); hash } end |
#to_json(*args) ⇒ Object
17 18 19 |
# File 'lib/unified_db/result/base.rb', line 17 def to_json(*args) UnifiedDB.json_encoder.encode to_h end |