Class: Glassfrog::Role
Overview
Encapsulates GlassFrog Roles.
Constant Summary collapse
- PATH =
'/roles'
- PATCH_PATH =
'/roles/0/links/people/'
- TYPE =
:roles
Instance Attribute Summary collapse
Attributes inherited from Base
Class Method Summary collapse
-
.get(client, options) ⇒ Array<Glassfrog::Role>
Sends a GET request for Role(s) to GlassFrog.
-
.patch(client, identifier, options) ⇒ Boolean
Sends a PATCH request to update a ChecklistItem on GlassFrog.
Instance Method Summary collapse
-
#name_parameterized ⇒ Symbol
Returns the name as a symbol with underscores instead of spaces.
Methods inherited from Base
Methods included from Utils
#extract_id, #parameterize, #symbolize_keys
Constructor Details
This class inherits a constructor from Glassfrog::Base
Instance Attribute Details
#links ⇒ Hash
13 14 15 |
# File 'lib/glassfrog/role.rb', line 13 def links @links end |
#name ⇒ String
11 12 13 |
# File 'lib/glassfrog/role.rb', line 11 def name @name end |
#purpose ⇒ String
11 12 13 |
# File 'lib/glassfrog/role.rb', line 11 def purpose @purpose end |
Class Method Details
.get(client, options) ⇒ Array<Glassfrog::Role>
Sends a GET request for Role(s) to GlassFrog.
24 25 26 27 |
# File 'lib/glassfrog/role.rb', line 24 def self.get(client, ) response = Glassfrog::REST::Get.get(client, PATH, ) response[TYPE].map { |object| self.new(object) } end |
.patch(client, identifier, options) ⇒ Boolean
Sends a PATCH request to update a ChecklistItem on GlassFrog. Only updates the People assigned to the Role.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/glassfrog/role.rb', line 36 def self.patch(client, identifier, ) path = PATH + '/' + identifier.to_s current_object = self.get(client, { id: identifier }).first = .is_a?(Glassfrog::Role) ? (.hashify) : () if current_object.links && current_object.links[:people] && [:people] ([:people] - current_object.links[:people]).each do |person_id| o = formify_role_patch({ person_id: person_id }, 'add') if !Glassfrog::REST::Patch.patch(client, path, o) then return false end end (current_object.links[:people] - [:people]).each do |person_id| o = formify_role_patch({ person_id: person_id }, 'remove') if !Glassfrog::REST::Patch.patch(client, path, o) then return false end end else raise(ArgumentError, "No people found") end true end |
Instance Method Details
#name_parameterized ⇒ Symbol
Returns the name as a symbol with underscores instead of spaces.
59 60 61 |
# File 'lib/glassfrog/role.rb', line 59 def name_parameterized parameterize(@name) end |