fresnel 0.6 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/fresnel.gemspec CHANGED
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
3
3
  s.name = 'fresnel'
4
4
  s.summary = "Fresnel is a console manager to LighthouseApp.com using the official lighthouse api."
5
5
  s.description = s.summary
6
- s.version = '0.6'
7
- s.date = '2010-01-04'
6
+ s.version = '0.6.1'
7
+ s.date = '2010-01-08'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Gerard de Brieder", "Wes Oldenbeuving"]
10
10
  s.email = "smeevil@gmail.com"
@@ -10,23 +10,26 @@ class SetupWizard
10
10
  puts " config wizard "
11
11
  puts "================================================"
12
12
  puts
13
- config['account']=ask("My lighthouse account is : ") do |q|
13
+ config['default_account']=ask("My lighthouse account is : ") do |q|
14
14
  q.validate = /^\w+$/
15
15
  q.responses[:not_valid]="\nError :\nThat seems to be incorrect, we would like to have the <account> part in\nhttp://<account>.lighthouseapp.com , please try again"
16
16
  q.responses[:ask_on_error]="My lighthouse account is : "
17
17
  q.default=config['account']||ENV['USER']
18
18
  end
19
-
19
+ config['accounts']=Hash.new
20
+ config['accounts'][config['default_account']]={'account'=>config['default_account']}
20
21
  puts
21
22
  puts "what token would you like to use for the account : #{config['account']} ?"
22
- config['token']=ask("My lighthouse token is : ") do |q|
23
+ config['accounts'][config['default_account']]['token']=ask("My lighthouse token is : ") do |q|
23
24
  q.validate = /^[0-9a-f]{40}$/
24
25
  q.responses[:not_valid]="\nError :\nThat seems to be incorrect, we would like to have your lighthouse token\n this looks something like : 1bd25cc2bab1fc4384b7edfe48433fba5f6ee43c"
25
26
  q.responses[:ask_on_error]="My lighthouse token is : "
26
27
  q.default=config['token'] if config['token']
27
28
  end
28
- Lighthouse.account=config['account']
29
- Lighthouse.token=config['token']
29
+ Lighthouse.account=config['accounts'][config['default_account']]['account']
30
+ Lighthouse.token=config['accounts'][config['default_account']]['token']
31
+
32
+
30
33
  user_id=Lighthouse::Token.get(fresnel.token)['user_id']
31
34
  config['user_id']=ask("My lighthouse user_id is : ", Integer) do |q|
32
35
  q.default=user_id
@@ -49,11 +52,17 @@ class SetupWizard
49
52
  data=fresnel.projects(:object=>true)
50
53
  current_dir=File.expand_path(".").split("/").last
51
54
  fresnel.projects(:selectable=>true, :clear=>false, :setup=>true)
52
- project_id=InputDetector.new("please select which project # resides here or [c]reate a new one : ", 0...data.size).answer
55
+ project_id=InputDetector.new("please select which project # resides here or [c]reate a new one or [a]dd an extra account : ", (0...data[:project_ids].size).to_a).answer
53
56
  if project_id=="c"
54
57
  fresnel.create_project
58
+ elsif project_id=="a"
59
+ fresnel.create_extra_account
55
60
  else
56
- config['project_id']=data[project_id.to_i].id
61
+ data[:project_ids][project_id.to_i]=~/^(\d+);(\w+)$/
62
+ id=$1
63
+ account=$2
64
+ config['project_id']=id
65
+ config['account_name']=account
57
66
  puts "generated your config in #{fresnel.project_config_file}, going on with main program..."
58
67
  # TODO: Refactor ProjectConfig into its own object, responsible for loading and saving itself.
59
68
  File.open(fresnel.project_config_file,'w+'){ |f| f.write(YAML::dump(config)) }
data/lib/fresnel.rb CHANGED
@@ -36,7 +36,6 @@ class Fresnel
36
36
  @cache=Cache.new
37
37
  load_global_config
38
38
  load_project_config
39
- initialize_lighthouse
40
39
  end
41
40
 
42
41
  def load_global_config
@@ -52,15 +51,20 @@ class Fresnel
52
51
  @@debug=config['debug'] if config.has_key?('debug')
53
52
  @@term_size=config['term_size'] if config.has_key?('term_size')
54
53
  @@tags=config['tags']
55
- unless config && config.class==Hash && config.has_key?('account') && config.has_key?('token') && config.has_key?('user_id') && config.has_key?('tags')
54
+ @@default_account=config['default_account']
55
+ @@accounts=config['accounts']
56
+
57
+
58
+ unless config && config.class==Hash && config.has_key?('default_account') && config.has_key?('user_id') && config.has_key?('tags')
56
59
  puts Frame.new(:header=>"Warning !",:body=>"global config did not validate , recreating")
57
60
  SetupWizard.global(self)
58
61
  return load_global_config
59
62
  end
60
63
 
61
- @lighthouse_account = config['account']
62
- @lighthouse_token = config['token']
64
+ @lighthouse_account = config['accounts'][@@default_account]['account']
65
+ @lighthouse_token = config['accounts'][@@default_account]['token']
63
66
  @current_user_id = config['user_id']
67
+ initialize_lighthouse
64
68
  nil
65
69
  end
66
70
 
@@ -78,11 +82,20 @@ class Fresnel
78
82
  end
79
83
 
80
84
  config = YAML.load_file(self.project_config_file) || Hash.new
81
- unless config['project_id']
82
- puts Frame.new(:header=>"Warning !",:body=>"project config found but project_id was not declared")
85
+ unless config.has_key?('project_id') && config.has_key?('account_name')
86
+ puts Frame.new(:header=>"Warning !",:body=>"project config found but did not validate, recreating ")
83
87
  return load_project_config
84
88
  end
89
+ if config.has_key?('account_name')
90
+ @lighthouse_account = @@accounts[config['account_name']]['account']
91
+ @lighthouse_token = @@accounts[config['account_name']]['token']
92
+ end
85
93
  @current_project_id = config['project_id']
94
+ @@tags=config['tags'] if config.has_key?('tags')
95
+ @@cache_timeout=config['cache_timeout'] if config.has_key?('cache_timeout')
96
+ @@debug=config['debug'] if config.has_key?('debug')
97
+ @@term_size=config['term_size'] if config.has_key?('term_size')
98
+ initialize_lighthouse
86
99
  nil
87
100
  end
88
101
 
@@ -126,36 +139,68 @@ class Fresnel
126
139
  end
127
140
 
128
141
  def projects(options=Hash.new)
142
+ system("clear")
129
143
  options[:object]||=false
130
144
  system("clear") unless options[:clear]==false || options[:object]
131
145
  options[:selectable]||false
132
- print "Fetching projects..." unless options[:object]
133
- projects_data=cache.load(:name=>"fresnel_projects",:action=>"Lighthouse::Project.find(:all)")
134
- puts " [done] - data is #{projects_data.age}s old , max is #{@@cache_timeout}s"
146
+ projects_data=Hash.new
147
+ project_ids=Array.new
148
+ if @@accounts.size>1
149
+ print "Fetching projects from multiple accounts : " unless options[:object]
150
+ @@accounts.each do |key,value|
151
+ print "#{key} "
152
+ STDOUT.flush
153
+ Lighthouse.account=value['account']
154
+ Lighthouse.token=value['token']
155
+ projects_data[Lighthouse.account]=Lighthouse::Project.find(:all)
156
+ end
157
+ puts " [done]"
158
+ else
159
+ print "Fetching projects..." unless options[:object]
160
+ #projects_data=cache.load(:name=>"fresnel_projects"){Lighthouse::Project.find(:all)} #no cache for now
161
+ projects_data[Lighthouse.account]=Lighthouse::Project.find(:all)
162
+ puts " [done]"
163
+ end
164
+
165
+ #puts " [done] - data is #{projects_data.age}s old , max is #{@@cache_timeout}s" #no cache for now
135
166
  project_table = table do |t|
136
167
  t.headings=[]
137
168
  t.headings << '#' if options[:selectable]
138
- t.headings += ['project name', 'public', 'open tickets']
139
-
140
- projects_data.each_with_index do |project,i|
141
- row=Array.new
142
- row << i if options[:selectable]
143
- row+=[project.name, project.public, {:value=>project.open_tickets_count, :alignment=>:right}]
144
- t << row
145
- end
169
+ t.headings += ["account"] if @@accounts.size>1
170
+ t.headings += [ 'project name', 'public', 'open tickets']
171
+ i=0
172
+ projects_data.each do |key,value|
173
+ value.each do |project|
174
+ row=Array.new
175
+ row << i if options[:selectable]
176
+ project_ids<<"#{project.id};#{key}"
177
+ row+=[key] if @@accounts.size>1
178
+ row+=[project.name, project.public, {:value=>project.open_tickets_count, :alignment=>:right}]
179
+ t << row
180
+ i+=1
181
+ end
182
+ end
146
183
  end
147
184
  if options[:object]
185
+ projects_data[:project_ids]=project_ids
148
186
  return projects_data
149
187
  else
150
188
  puts(project_table)
151
189
  unless options[:setup]
152
- action=InputDetector.new("[q]uit, [c]reate or project #",(0...projects_data.size).to_a).answer
190
+ action=InputDetector.new("[q]uit, [c]reate or project #",(0..project_ids.size).to_a).answer
153
191
  puts "action is #{action.inspect}"
154
192
  case action
155
193
  when "c" then create_project
156
- when /\d+/ then tickets(:project_id=>projects_data[action.to_i].id)
194
+ when /\d+/ then
195
+ project_ids[action.to_i]=~/(\d+);(\w+)/
196
+ project_id=$1
197
+ account=$2
198
+
199
+ Lighthouse.account=@@accounts[account]["account"]
200
+ Lighthouse.token=@@accounts[account]["token"]
201
+
202
+ tickets(:project_id=>project_id)
157
203
  else
158
- puts "dont know what to do with #{action.inspect} class #{action.class}"
159
204
  exit(0)
160
205
  end
161
206
  end
@@ -549,4 +594,27 @@ class Fresnel
549
594
  end
550
595
  show_ticket(options[:ticket])
551
596
  end
597
+
598
+ def create_extra_account
599
+ config=YAML::load_file(self.global_config_file)
600
+
601
+ puts "should add an extra account !"
602
+ config['account']=ask("My extra lighthouse account is : ") do |q|
603
+ q.validate = /^\w+$/
604
+ q.responses[:not_valid]="\nError :\nThat seems to be incorrect, we would like to have the <account> part in\nhttp://<account>.lighthouseapp.com , please try again"
605
+ q.responses[:ask_on_error]="My extra account is : "
606
+ end
607
+
608
+ config['accounts'][config['account']]={'account'=>config['account']}
609
+ puts
610
+ puts "what token would you like to use for the account : #{config['account']} ?"
611
+ config['accounts'][config['account']]['token']=ask("My lighthouse token is : ") do |q|
612
+ q.validate = /^[0-9a-f]{40}$/
613
+ q.responses[:not_valid]="\nError :\nThat seems to be incorrect, we would like to have your lighthouse token\n this looks something like : 1bd25cc2bab1fc4384b7edfe48433fba5f6ee43c"
614
+ q.responses[:ask_on_error]="My lighthouse token is : "
615
+ q.default=config['token'] if config['token']
616
+ end
617
+ File.open(self.global_config_file,'w+'){ |f| f.write(YAML::dump(config)) }
618
+ load_global_config
619
+ end
552
620
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fresnel
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.6"
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerard de Brieder
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-04 00:00:00 +01:00
13
+ date: 2010-01-08 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency