Class: Glassfrog::Role

Inherits:
Base
  • Object
show all
Defined in:
lib/glassfrog/role.rb

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

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==, #hashify, #initialize

Methods included from Utils

#extract_id, #parameterize, #symbolize_keys

Constructor Details

This class inherits a constructor from Glassfrog::Base

Instance Attribute Details

Returns:

  • (Hash)


13
14
15
# File 'lib/glassfrog/role.rb', line 13

def links
  @links
end

#nameString

Returns:

  • (String)


11
12
13
# File 'lib/glassfrog/role.rb', line 11

def name
  @name
end

#purposeString

Returns:

  • (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.

Parameters:

  • client (Glassfrog::Client)

    The client that will send the request. Contains the API key.

  • options (Hash, Glassfrog::Base)

    The options used to find the correct Roles(s).

Returns:

  • (Array<Glassfrog::Role>)

    The array of Role(s) fetched from GlassFrog.



24
25
26
27
# File 'lib/glassfrog/role.rb', line 24

def self.get(client, options)
  response = Glassfrog::REST::Get.get(client, PATH, options)
  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.

Parameters:

  • client (Glassforg::Client)

    The client that will send the request. Contains the API key.

  • identifier (Integer)

    The ID of the ChecklistItem to be updated.

  • options (Hash, Glassfrog::Base)

    The options used to update the ChecklistItem.

Returns:

  • (Boolean)

    Whether the request failed or not.



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, options)
  path = PATH + '/' + identifier.to_s
  current_object = self.get(client, { id: identifier }).first
  options = options.is_a?(Glassfrog::Role) ? parse_options(options.hashify) : parse_options(options)
  if current_object.links && current_object.links[:people] && options[:people]
    (options[: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] - options[: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_parameterizedSymbol

Returns the name as a symbol with underscores instead of spaces.

Returns:

  • (Symbol)

    The name as a symbol.



59
60
61
# File 'lib/glassfrog/role.rb', line 59

def name_parameterized
  parameterize(@name)
end