Class: TicketMaster::Provider::Github::Project

Inherits:
Base::Project
  • Object
show all
Defined in:
lib/provider/project.rb

Overview

Project class for ticketmaster-github

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Project

declare needed overloaded methods here



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/provider/project.rb', line 9

def initialize(*object) 
  if object.first
    object = object.first
    @system_data = {:client => object} 
    unless object.is_a? Hash
      hash = {:description => object.description,
              :created_at => object.created_at,
              :updated_at => object.created_at,
              :name => object.name,
              :id => object.name,
              :owner => object.owner}
    else 
      hash = object
    end 
    super hash
  end
end

Class Method Details

.find(*options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/provider/project.rb', line 58

def self.find(*options)
  if options[0].empty?
    projects = self.find_all
  elsif options[0].first.is_a? Array
    options[0].first.collect { |name| self.find_by_id(name) }
  elsif options[0].first.is_a? String
    self.find_by_id(options[0].first)
  elsif options[0].first.is_a? Hash
    self.find_by_attributes(options[0].first)
  end
end

.find_allObject



79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/provider/project.rb', line 79

def self.find_all
  repos = []
  user_repos = TicketMaster::Provider::Github.api.repositories(TicketMaster::Provider::Github.).collect { |repository| 
    self.new repository }
    repos = repos + user_repos
    if TicketMaster::Provider::Github.valid_user
      org_repos = TicketMaster::Provider::Github.api.organization_repositories.collect { |repository| 
        self.new repository }
        repos = repos + org_repos
    end
    repos
end

.find_by_attributes(attributes = {}) ⇒ Object



70
71
72
# File 'lib/provider/project.rb', line 70

def self.find_by_attributes(attributes = {})
  search_by_attribute(self.find_all, attributes)
end

.find_by_id(id) ⇒ Object



74
75
76
77
# File 'lib/provider/project.rb', line 74

def self.find_by_id(id)
  id = "#{TicketMaster::Provider::Github.}/#{id}" unless id.include?("/")
  self.new TicketMaster::Provider::Github.api.repository(id) 
end

Instance Method Details

#copy(project) ⇒ Object

copy from this.copy(that) copies that into this



48
49
50
51
52
53
54
55
56
# File 'lib/provider/project.rb', line 48

def copy(project)
  project.tickets.each do |ticket|
    copy_ticket = self.ticket!(:title => ticket.title, :description => ticket.description)
    ticket.comments.each do |comment|
      copy_ticket.comment!(:body => comment.body)
      sleep 1
    end
  end
end

#created_atObject



27
28
29
30
31
32
33
# File 'lib/provider/project.rb', line 27

def created_at
  begin 
    Time.parse(self[:created_at]) 
  rescue
    self[:created_at]
  end
end

#idObject



43
44
45
# File 'lib/provider/project.rb', line 43

def id
  "#{self.owner.}/#{self[:name]}"
end

#ticket(*options) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/provider/project.rb', line 96

def ticket(*options)
  unless options.empty?
    TicketMaster::Provider::Github::Ticket.find_by_id(self.id, options.first)
  else
    TicketMaster::Provider::Github::Ticket
  end
end

#ticket!(*options) ⇒ Object



104
105
106
# File 'lib/provider/project.rb', line 104

def ticket!(*options)
  TicketMaster::Provider::Github::Ticket.open(self.id, options.first)
end

#tickets(*options) ⇒ Object



92
93
94
# File 'lib/provider/project.rb', line 92

def tickets(*options)
  TicketMaster::Provider::Github::Ticket.find(self.id, options)
end

#updated_atObject



35
36
37
38
39
40
41
# File 'lib/provider/project.rb', line 35

def updated_at
  begin
    Time.parse(self[:created_at]) 
  rescue
    self[:created_at]
  end
end