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.



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
41
42
# File 'lib/helm/session.rb', line 9

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
  @cache = Drawer.open!('.helm/cache')

  configure
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



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

def cache
  @cache
end

#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.



54
55
56
# File 'lib/helm/session.rb', line 54

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

#configure_params(*names) ⇒ Object

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



45
46
47
48
49
50
# File 'lib/helm/session.rb', line 45

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

#milestone(id = nil) ⇒ Object



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

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



62
63
64
# File 'lib/helm/session.rb', line 62

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

#passwordObject



102
103
104
# File 'lib/helm/session.rb', line 102

def password
  options.password
end

#projectObject



58
59
60
# File 'lib/helm/session.rb', line 58

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

#ticket(id = nil) ⇒ Object



66
67
68
# File 'lib/helm/session.rb', line 66

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

#ticket_path(id = nil) ⇒ Object



106
107
108
# File 'lib/helm/session.rb', line 106

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

#tickets(filter = nil) ⇒ Object



70
71
72
# File 'lib/helm/session.rb', line 70

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

#uriObject



90
91
92
# File 'lib/helm/session.rb', line 90

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

#urlObject



94
95
96
# File 'lib/helm/session.rb', line 94

def url
  options.url
end

#user(id = nil) ⇒ Object



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

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

#usernameObject



98
99
100
# File 'lib/helm/session.rb', line 98

def username
  options.username
end