Class: Helm::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/helm/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/helm/session.rb', line 8

def initialize
  Choice.options do
    option :url do
      long '--url'
      desc 'The project URL'
    end

    option :token do
      long '--token'
      desc 'The token to authenticate against the server'
    end

    option :username do
      long '--username'
      desc 'The username to authenticate against the server'
    end

    option :password do
      long '--password'
      desc 'The username to authenticate against the server'
    end

    option :project do
      long '--project'
      short '-p'
      desc 'The project title'
    end
  end

  @options = Choice.choices

  configure
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/helm/session.rb', line 6

def options
  @options
end

Instance Method Details

#[](name) ⇒ Object

Access positional parameters sent to the active command based on the order specified in configure_params.



52
53
54
# File 'lib/helm/session.rb', line 52

def [](name)
  arguments[@params[name].succ]
end

#configure_params(*names) ⇒ Object

Configure the set of params to be used by the active command.



43
44
45
46
47
48
# File 'lib/helm/session.rb', line 43

def configure_params(*names)
  @params = {}
  names.each_with_index do |name, index|
    @params[name] = index
  end
end

#milestone(id = nil) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/helm/session.rb', line 72

def milestone(id = nil)
  if id
    Lighthouse::Milestone.find(id)
  else
    @milestone ||= Lighthouse::Milestone.find(:all, :params => {:project_id => project.id}).detect {|m| m.title == self[:milestone] }
  end
end

#new_ticketObject



60
61
62
# File 'lib/helm/session.rb', line 60

def new_ticket
  Lighthouse::Ticket.new(:project_id => project.id)
end

#passwordObject



100
101
102
# File 'lib/helm/session.rb', line 100

def password
  options.password
end

#projectObject



56
57
58
# File 'lib/helm/session.rb', line 56

def project
  @project ||= Lighthouse::Project.find(:all).detect {|p| p.name == options.project }
end

#ticket(id = nil) ⇒ Object



64
65
66
# File 'lib/helm/session.rb', line 64

def ticket(id = nil)
  Lighthouse::Ticket.find(id || self[:ticket], :params => {:project_id => project.id})
end

#ticket_path(id = nil) ⇒ Object



104
105
106
# File 'lib/helm/session.rb', line 104

def ticket_path(id = nil)
  Lighthouse::Ticket.element_path(id || self[:ticket], {:project_id => project.id}).sub(/\.xml$/, '')
end

#tickets(filter = nil) ⇒ Object



68
69
70
# File 'lib/helm/session.rb', line 68

def tickets(filter = nil)
  project.tickets(:q => filter)
end

#uriObject



88
89
90
# File 'lib/helm/session.rb', line 88

def uri
  @uri ||= URI.parse(url)
end

#urlObject



92
93
94
# File 'lib/helm/session.rb', line 92

def url
  options.url
end

#user(id = nil) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/helm/session.rb', line 80

def user(id = nil)
  if id
    Lighthouse::User.find(id)
  else
    @user ||= Lighthouse::User.find(Lighthouse::Token.find(token).user_id)
  end
end

#usernameObject



96
97
98
# File 'lib/helm/session.rb', line 96

def username
  options.username
end