Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/glassfrog/accountability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
require 'glassfrog/base'

module Glassfrog
#
# Encapsulates GlassFrog Accountability
#
class Accountability < Glassfrog::Base
# @return [String]
attr_accessor :description
end
end

17 changes: 16 additions & 1 deletion lib/glassfrog/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,20 @@ def hashify
self.instance_variables.each { |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
symbolize_keys(hash)
end

def build_link_objects(response)
link_types.each do |type|
build_link_objects_with_type(response, type)
end
end

def build_link_objects_with_type(response, type)
link_objects = links[type].map do |link_id|
links = response[:linked][type]
attributes = links.detect { |link| link[:id] == link_id }
LinkFactory.build(type, attributes)
end
self.send("#{type}=", link_objects)
end
end
end
end
18 changes: 15 additions & 3 deletions lib/glassfrog/circle.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'glassfrog/base'
require 'glassfrog/rest/get'
require 'glassfrog/role'
require 'glassfrog/link_factory'

module Glassfrog
#
Expand All @@ -9,12 +11,18 @@ class Circle < Glassfrog::Base
# @return [String]
attr_accessor :name, :short_name, :strategy
# @return [Hash]
attr_accessor :links
attr_accessor :links, :roles
# @return [Array<Glassfrog::Circle]
attr_accessor :sub_circles
PATH = '/circles'
TYPE = :circles

LinkFactory.register(:roles, Role)

def link_types
[:roles]
end

#
# Sends a GET request for Circle(s) to GlassFrog.
# @param client [Glassfrog::Client] The client that will send the request. Contains the API key.
Expand All @@ -23,7 +31,11 @@ class Circle < Glassfrog::Base
# @return [Array<Glassfrog::Circle>] The array of Circle(s) fetched from GlassFrog.
def self.get(client, options)
response = Glassfrog::REST::Get.get(client, PATH, options)
response[TYPE].map { |object| self.new(object) }
response[TYPE].map do |object|
circle = self.new(object)
circle.build_link_objects(response)
circle
end
end
end
end
end
11 changes: 11 additions & 0 deletions lib/glassfrog/domain.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'glassfrog/base'

module Glassfrog
#
# Encapsulates GlassFrog Accountability
#
class Domain < Glassfrog::Base
# @return [String]
attr_accessor :description
end
end
16 changes: 16 additions & 0 deletions lib/glassfrog/link_factory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Glassfrog
class LinkFactory
@@config = {}

def self.register(key, klass)
@@config[key] = klass
end

def self.build(link_type, attributes)
klass = @@config[link_type]
object = klass.new(attributes)
object
end
end
end

2 changes: 1 addition & 1 deletion lib/glassfrog/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ def self.parse_options(options)
params_hash
end
end
end
end
22 changes: 19 additions & 3 deletions lib/glassfrog/role.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'glassfrog/base'
require 'glassfrog/rest/get'
require 'glassfrog/rest/patch'
require 'glassfrog/link_factory'
require 'glassfrog/accountability'
require 'glassfrog/domain'
require 'glassfrog/person'

module Glassfrog
#
Expand All @@ -10,11 +14,19 @@ class Role < Glassfrog::Base
# @return [String]
attr_accessor :name, :purpose
# @return [Hash]
attr_accessor :links
attr_accessor :links, :accountabilities, :domains, :people
PATH = '/roles'
PATCH_PATH = '/roles/0/links/people/'
TYPE = :roles

LinkFactory.register(:accountabilities, Accountability)
LinkFactory.register(:domains, Domain)
LinkFactory.register(:people, Person)

def link_types
[:accountabilities, :domains, :people]
end

#
# Sends a GET request for Role(s) to GlassFrog.
# @param client [Glassfrog::Client] The client that will send the request. Contains the API key.
Expand All @@ -23,7 +35,11 @@ class Role < Glassfrog::Base
# @return [Array<Glassfrog::Role>] The array of Role(s) fetched from GlassFrog.
def self.get(client, options)
response = Glassfrog::REST::Get.get(client, PATH, options)
response[TYPE].map { |object| self.new(object) }
response[TYPE].map do |object|
role = self.new(object)
role.build_link_objects(response)
role
end
end

#
Expand Down Expand Up @@ -91,4 +107,4 @@ def self.formify_role_patch(options, operation)
end
end
end
end
end