Class: Helm::Session
- Inherits:
-
Object
- Object
- Helm::Session
- Defined in:
- lib/helm/session.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Access positional parameters sent to the active command based on the order specified in configure_params.
-
#configure_params(*names) ⇒ Object
Configure the set of params to be used by the active command.
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #milestone(id = nil) ⇒ Object
- #new_ticket ⇒ Object
- #password ⇒ Object
- #project ⇒ Object
- #ticket(id = nil) ⇒ Object
- #ticket_path(id = nil) ⇒ Object
- #tickets(filter = nil) ⇒ Object
- #uri ⇒ Object
- #url ⇒ Object
- #user(id = nil) ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize ⇒ Session
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. 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
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
7 8 9 |
# File 'lib/helm/session.rb', line 7 def cache @cache end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/helm/session.rb', line 6 def @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_ticket ⇒ Object
62 63 64 |
# File 'lib/helm/session.rb', line 62 def new_ticket Lighthouse::Ticket.new(:project_id => project.id) end |
#password ⇒ Object
102 103 104 |
# File 'lib/helm/session.rb', line 102 def password .password end |
#project ⇒ Object
58 59 60 |
# File 'lib/helm/session.rb', line 58 def project @project ||= Lighthouse::Project.find(:all).detect {|p| p.name == .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 |
#uri ⇒ Object
90 91 92 |
# File 'lib/helm/session.rb', line 90 def uri @uri ||= URI.parse(url) end |
#url ⇒ Object
94 95 96 |
# File 'lib/helm/session.rb', line 94 def url .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 |
#username ⇒ Object
98 99 100 |
# File 'lib/helm/session.rb', line 98 def username .username end |