Class: GoodData::ProjectRole

Inherits:
Rest::Resource show all
Includes:
Mixin::Author, Mixin::Contributor, Mixin::Timestamps
Defined in:
lib/gooddata/models/project_role.rb

Constant Summary collapse

EMPTY_OBJECT =
{
  'projectRole' => {
    'permissions' => {},
    'links' => {},
    'meta' => {}
  }
}

Instance Attribute Summary

Attributes inherited from Rest::Object

#client, #json, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Timestamps

#created, #updated

Methods included from Mixin::Contributor

#contributor

Methods included from Mixin::Author

#author, #author_uri

Methods included from Mixin::ObjId

#obj_id

Methods inherited from Rest::Object

client, default_client, #saved?

Methods included from Mixin::DataPropertyReader

#data_property_reader

Methods included from Mixin::DataPropertyWriter

#data_property_writer

Methods included from Mixin::MetaPropertyReader

#metadata_property_reader

Methods included from Mixin::MetaPropertyWriter

#metadata_property_writer

Methods included from Mixin::MetaGetter

#meta

Methods included from Mixin::DataGetter

#data

Methods included from Mixin::RootKeyGetter

#root_key

Methods included from Mixin::ContentGetter

#content

Constructor Details

#initialize(json) ⇒ ProjectRole

Returns a new instance of ProjectRole.



46
47
48
# File 'lib/gooddata/models/project_role.rb', line 46

def initialize(json)
  @json = json
end

Class Method Details

.create_object(data) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gooddata/models/project_role.rb', line 29

def self.create_object(data)
   = {}.tap do |d|
    d[:created] = data[:created] || Time.now
    d[:identifier] = data[:identifier]
    d[:updated] = data[:updated] || d[:created] || Time.now
    d[:title] = data[:title]
    d[:summary] = data[:summary]
    d[:uri] = data[:uri]
  end
  new_data = GoodData::Helpers.deep_dup(EMPTY_OBJECT).tap do |d|
    d['projectRole']['links']['self'] = data[:uri] if data[:uri]
    d['projectRole']['meta'] = d['projectRole']['meta'].merge(GoodData::Helpers.stringify_keys())
    d['projectRole']['permissions'] = d['projectRole']['permissions'].merge(GoodData::Helpers.stringify_keys(data[:permissions] || {}))
  end
  new(new_data)
end

Instance Method Details

#==(other) ⇒ Object



74
75
76
# File 'lib/gooddata/models/project_role.rb', line 74

def ==(other)
  uri == other.uri
end

#uristring

Gets Raw object URI

Returns:

  • (string)

    URI of this project role



70
71
72
# File 'lib/gooddata/models/project_role.rb', line 70

def uri
  @json['projectRole']['meta']['uri']
end

#usersArray<GoodData::Profile>

Gets Users with this Role

Returns:



57
58
59
60
61
62
63
64
65
# File 'lib/gooddata/models/project_role.rb', line 57

def users
  url = uri + '/users'
  tmp = client.get url
  tmp['associatedUsers']['users'].pmap do |user_url|
    url = user_url
    user = client.get url
    client.create(GoodData::Profile, user)
  end
end