Class: Representation

Inherits:
Object
  • Object
show all
Includes:
KeycloakAdmin::CamelJson
Defined in:
lib/keycloak-admin/representation/representation.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from KeycloakAdmin::CamelJson

#camelize

Class Method Details

.from_json(json) ⇒ Object



19
20
21
22
# File 'lib/keycloak-admin/representation/representation.rb', line 19

def self.from_json(json)
  hash = JSON.parse(json)
  from_hash(hash)
end

Instance Method Details

#as_json(options = nil) ⇒ Object



7
8
9
# File 'lib/keycloak-admin/representation/representation.rb', line 7

def as_json(options=nil)
  Hash[instance_variables.map { |ivar| [ivar.to_s[1..-1], instance_variable_get(ivar)] }]
end

#to_json(options = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/keycloak-admin/representation/representation.rb', line 11

def to_json(options=nil)
  snaked_hash = as_json(options)
  snaked_hash.keys.reduce({}) do |camelized_hash, key|
    camelized_hash[camelize(key, false)] = snaked_hash[key]
    camelized_hash
  end.to_json(options)
end