Class: PGit::Project

Inherits:
PGit::Pivotal::IndividualRequest show all
Extended by:
Helpers::QueryMethods
Includes:
ActiveModel::Validations, Helpers::QueryMethods
Defined in:
lib/pgit/project.rb,
lib/pgit/project/add.rb,
lib/pgit/project/remove.rb,
lib/pgit/project/application.rb,
lib/pgit/project/interactive_adder.rb,
lib/pgit/project/reuse_api_token_adder.rb

Defined Under Namespace

Classes: Add, Application, InteractiveAdder, Remove, ReuseApiTokenAdder

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::QueryMethods

attr_given, attr_has, attr_query, defaulted_attrs, ensure_given_attr, ensure_given_queries, given_attrs, not_given, set_attr, set_default_attr, set_default_queries

Methods inherited from PGit::Pivotal::IndividualRequest

#define_methods, #get!, #hash=, #put!

Methods inherited from PGit::Pivotal::Request

#api_version, #before_initialize, #current_project, #get_request, #link

Constructor Details

#initialize(configuration = :no_config_given, proj = {}) {|_self| ... } ⇒ Project

Returns a new instance of Project.

Yields:

  • (_self)

Yield Parameters:

  • _self (PGit::Project)

    the object that the method was called on



15
16
17
18
19
20
21
22
23
# File 'lib/pgit/project.rb', line 15

def initialize(configuration=:no_config_given,
               proj={},
               &block)
  yield self if block_given?
  @query_hash = proj
  @configuration = configuration
  @cmds = proj.fetch('commands') { Array.new }
  set_default_queries
end

Instance Attribute Details

#api_tokenObject

Returns the value of attribute api_token.



12
13
14
# File 'lib/pgit/project.rb', line 12

def api_token
  @api_token
end

#configurationObject (readonly)

Returns the value of attribute configuration.



12
13
14
# File 'lib/pgit/project.rb', line 12

def configuration
  @configuration
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/pgit/project.rb', line 12

def id
  @id
end

#kindObject (readonly)

Returns the value of attribute kind.



12
13
14
# File 'lib/pgit/project.rb', line 12

def kind
  @kind
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/pgit/project.rb', line 12

def path
  @path
end

Instance Method Details

#commandsObject



29
30
31
# File 'lib/pgit/project.rb', line 29

def commands
  build_commands(@cmds)
end

#commands=(some_commands) ⇒ Object



25
26
27
# File 'lib/pgit/project.rb', line 25

def commands=(some_commands)
  @cmds = some_commands
end

#exists?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/pgit/project.rb', line 53

def exists?
  configuration.projects.find {|p| p.path == path}
end

#remove!Object



49
50
51
# File 'lib/pgit/project.rb', line 49

def remove!
  remove_old_copy
end

#save!Object

Raises:



42
43
44
45
46
47
# File 'lib/pgit/project.rb', line 42

def save!
  ensure_given_queries
  raise PGit::Error::User, errors.full_messages.first unless valid?

  remove_old_copy { configuration.projects = configuration.projects << self }
end


57
58
59
# File 'lib/pgit/project.rb', line 57

def sublink
  "projects/#{id}"
end

#to_hashObject



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

def to_hash
  {
    "path" => path,
    "api_token" => api_token,
    "id" => id,
    "commands" => commands.map {|cmd| cmd.to_hash}
  }
end