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



21
22
23
24
# File 'lib/keycloak-admin/representation/representation.rb', line 21

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

Instance Method Details

#as_json(options = nil) ⇒ Object



8
9
10
11
12
13
# File 'lib/keycloak-admin/representation/representation.rb', line 8

def as_json(options=nil)
  instance_variables.each_with_object({}) do |ivar, hash|
    val = instance_variable_get(ivar)
    hash[ivar.to_s[1..-1]] = val unless val.nil?
  end
end

#to_json(options = nil) ⇒ Object



15
16
17
18
19
# File 'lib/keycloak-admin/representation/representation.rb', line 15

def to_json(options=nil)
  as_json(options).each_with_object({}) do |(key, val), hash|
    hash[camelize(key, false)] = val
  end.to_json(options)
end