Class: UnifiedDB::Result::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/unified_db/result/base.rb

Direct Known Subclasses

ID, Title

Class Method Summary collapse

Instance Method Summary collapse

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_keysObject



5
# File 'lib/unified_db/result/base.rb', line 5

def self.allowed_keys; []; end

Instance Method Details

#to_hObject



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