Class: GoodData::Command::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/gooddata/commands/project.rb

Class Method Summary collapse

Class Method Details

.build(opts = { client: GoodData.connection }) ⇒ Object

Build project



91
92
93
94
95
96
# File 'lib/gooddata/commands/project.rb', line 91

def build(opts = { client: GoodData.connection })
  client = opts[:client]
  fail ArgumentError, 'No :client specified' if client.nil?

  GoodData::Model::ProjectCreator.migrate(opts.merge(:client => client))
end

.clone(project_id, options = { client: GoodData.connection }) ⇒ Object

Clone existing project

Parameters:

  • project_id (String | GoodData::Project)

    Project id or project instance to delete

  • options (Hash) (defaults to: { client: GoodData.connection })

    a customizable set of options

Options Hash (options):

  • :data (String)

    Clone including all the data (default true)

  • :users (String)

    Clone including all the users (default false)

  • :title (String)

    Name of the cloned project (default "Clone of old_project_title")

  • :exclude_schedules (Boolean)

    Specifies whether to include scheduled emails

  • :verbose (Boolean) — default: false

    Switch on verbose mode for detailed logging



49
50
51
52
53
54
# File 'lib/gooddata/commands/project.rb', line 49

def clone(project_id, options = { client: GoodData.connection })
  client = options[:client]
  client.with_project(project_id) do |project|
    project.clone(options)
  end
end

.create(options = { client: GoodData.connection }) ⇒ Object

Create new project based on options supplied



17
18
19
20
21
22
23
24
25
# File 'lib/gooddata/commands/project.rb', line 17

def create(options = { client: GoodData.connection })
  title = options[:title]
  summary = options[:summary]
  template = options[:template]
  token = options[:token]
  client = options[:client]
  driver = options[:driver] || 'Pg'
  GoodData::Project.create(:title => title, :summary => summary, :template => template, :auth_token => token, :client => client, :driver => driver)
end

.delete(project_id, options = { client: GoodData.connection }) ⇒ Object

Deletes existing project

Parameters:

  • project_id (String | GoodData::Project)

    Project id or project instance to delete



59
60
61
62
63
# File 'lib/gooddata/commands/project.rb', line 59

def delete(project_id, options = { client: GoodData.connection })
  client = options[:client]
  p = client.projects(project_id)
  p.delete
end

.get_spec_and_project_id(base_path) ⇒ Object

Get Spec and ID (of project)



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gooddata/commands/project.rb', line 66

def get_spec_and_project_id(base_path)
  goodfile_path = GoodData::Helpers.find_goodfile(Pathname(base_path))
  fail 'Goodfile could not be located in any parent directory. Please make sure you are inside a gooddata project folder.' if goodfile_path.nil?
  goodfile = JSON.parse(File.read(goodfile_path), :symbolize_names => true)
  spec_path = goodfile[:model] || fail('You need to specify the path of the build spec')
  fail "Model path provided in Goodfile \"#{spec_path}\" does not exist" unless File.exist?(spec_path) && !File.directory?(spec_path)

  spec_path = Pathname(spec_path)

  content = File.read(spec_path)
  spec = if spec_path.extname == '.rb'
           eval(content)
         elsif spec_path.extname == '.json'
           JSON.parse(spec_path, :symbolize_names => true)
         end
  [spec, goodfile[:project_id]]
end

.invite(project_id, email, role, msg = GoodData::Project::DEFAULT_INVITE_MESSAGE, options = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/gooddata/commands/project.rb', line 33

def invite(project_id, email, role, msg = GoodData::Project::DEFAULT_INVITE_MESSAGE, options = {})
  client = options[:client]
  project = client.projects(project_id)
  fail "Invalid project id '#{project_id}' specified" if project.nil?

  project.invite(email, role, msg)
end

.list_users(options = { client: GoodData.connection }) ⇒ Object

Lists users in a project

TODO: Review and refactor #users & #list_users

Parameters:

  • options (Hash) (defaults to: { client: GoodData.connection })

    List of users



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/gooddata/commands/project.rb', line 130

def list_users(options = { client: GoodData.connection })
  client = GoodData.connect(options)
  project = client.projects(options[:project_id])

  rows = project.users.to_a.map do |user|
    [user.email, user.full_name, user.role.title, user.user_groups.join(', ')]
  end

  table = Terminal::Table.new :headings => ['Email', 'Full Name', 'Role', 'Groups'], :rows => rows
  puts table
end

.roles(project_id, options = { client: GoodData.connection }) ⇒ Array <GoodData::Role>

Lists roles in a project

Parameters:

  • project_id (String | GoodData::Project)

    Project id or project instance to list the users in

Returns:

  • (Array <GoodData::Role>)

    List of project roles



111
112
113
114
# File 'lib/gooddata/commands/project.rb', line 111

def roles(project_id, options = { client: GoodData.connection })
  client = options[:client]
  client.with_project(project_id, &:roles)
end

.show(id, options = { client: GoodData.connection }) ⇒ Object

Show existing project



28
29
30
31
# File 'lib/gooddata/commands/project.rb', line 28

def show(id, options = { client: GoodData.connection })
  client = options[:client]
  client.projects(id)
end

.update(opts = { client: GoodData.connection }) ⇒ Object

Update project



85
86
87
88
# File 'lib/gooddata/commands/project.rb', line 85

def update(opts = { client: GoodData.connection })
  client, project = GoodData.get_client_and_project(opts)
  GoodData::Model::ProjectCreator.migrate(:spec => opts[:spec], :client => client, :project => project)
end

.users(project_id, options = { client: GoodData.connection }) ⇒ Array <GoodData::Membership>

Lists users in a project

Parameters:

  • project_id (String | GoodData::Project)

    Project id or project instance to list the users in

Returns:



120
121
122
123
# File 'lib/gooddata/commands/project.rb', line 120

def users(project_id, options = { client: GoodData.connection })
  client = options[:client] || GoodData.connect(options)
  client.with_project(project_id, &:users)
end

.validate(project_id, options = { client: GoodData.connection }) ⇒ Object

Performs project validation

Parameters:

  • project_id (String | GoodData::Project)

    Project id or project instance to validate

Returns:

  • (Object)

    Report of found problems



102
103
104
105
# File 'lib/gooddata/commands/project.rb', line 102

def validate(project_id, options = { client: GoodData.connection })
  client = options[:client]
  client.with_project(project_id, &:validate)
end