Class: GithubPivotalFlow::Project

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Project

Returns a new instance of Project.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/github_pivotal_flow/project.rb', line 10

def initialize(args = {})
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
  url = Git.get_config("remote.#{Git.get_remote}.url")
  if (matchdata = /^git@([a-z0-9\._-]+):([a-z0-9_-]+)\/([a-z0-9_-]+)(\.git)?$/i.match(url.strip))
    self.host ||= matchdata[1]
    self.owner ||= matchdata[2]
    self.name ||= matchdata[3]
  else
    url = URI(url) if !url.is_a?(URI)
    path_components = url.path.split('/', 4)
    self.owner ||= path_components[1]
    self.name ||= path_components[2]
    self.host ||= url.host
  end
  self.name = self.name.tr(' ', '-').sub(/\.git$/, '') if self.name
  self.name ||= File.basename(Dir.getwd)
  self.host ||= 'github.com'
  self.host = host.sub(/^ssh\./i, '') if 'ssh.github.com' == host.downcase
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



44
45
46
# File 'lib/github_pivotal_flow/project.rb', line 44

def method_missing(m, *args, &block)
  return pivotal_project.send(m, *args, &block)
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



3
4
5
# File 'lib/github_pivotal_flow/project.rb', line 3

def config
  @config
end

#hostObject

Returns the value of attribute host.



3
4
5
# File 'lib/github_pivotal_flow/project.rb', line 3

def host
  @host
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/github_pivotal_flow/project.rb', line 3

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



3
4
5
# File 'lib/github_pivotal_flow/project.rb', line 3

def owner
  @owner
end

Class Method Details

.find(id) ⇒ Object



5
6
7
8
# File 'lib/github_pivotal_flow/project.rb', line 5

def self.find(id)
  id = id.to_i if id.is_a?(String)
  return PivotalTracker::Project.find(id)
end

Instance Method Details

#==(other) ⇒ Object



36
37
38
# File 'lib/github_pivotal_flow/project.rb', line 36

def ==(other)
  name_with_owner == other.name_with_owner
end

#name_with_ownerObject



32
33
34
# File 'lib/github_pivotal_flow/project.rb', line 32

def name_with_owner
  "#{owner}/#{name}"
end

#pivotal_projectObject



40
41
42
# File 'lib/github_pivotal_flow/project.rb', line 40

def pivotal_project
  @pivotal_project ||= self.class.find(self.config.project_id)
end