Skip to content

Instantly share code, notes, and snippets.

@sebastiangeiger
Last active August 29, 2015 14:11
Show Gist options
  • Save sebastiangeiger/5dc2018b64be97827c49 to your computer and use it in GitHub Desktop.
Save sebastiangeiger/5dc2018b64be97827c49 to your computer and use it in GitHub Desktop.
require 'json'
require 'lazy_doc'
json = '{"first_name": "George", "last_name": "Washington", "worker_number": "0000001", "email": "george@gmail.com", "user_name": "georgie", "profile_roles" : [ { "project_name": "Work!", "role" : "PROJECT_ADMINISTRATOR" } ]}'
class User
include LazyDoc::DSL
def initialize(json)
lazily_embed(json)
end
access :first_name
access :last_name
access :profile_roles, finally: lambda {|profile_roles| profile_roles.map{|profile_role| ProfileRole.new(profile_role)}}
end
class ProfileRole
include LazyDoc::DSL
def initialize(json)
lazily_embed(json)
end
access :project_name
access :role
end
u = User.new(json)
p u.first_name
p u.last_name
p u.profile_roles
p u.profile_roles.first.project_name
p u.profile_roles.first.role
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment