Class: GitStoryid::Configuration
- Inherits:
-
Object
- Object
- GitStoryid::Configuration
show all
- Defined in:
- lib/git_storyid.rb
Constant Summary
collapse
- FILENAME =
%w(.git-storyid)
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Configuration.
220
221
222
223
|
# File 'lib/git_storyid.rb', line 220
def initialize(config)
@config = config
setup_api_client
end
|
Class Method Details
.build ⇒ Object
150
151
152
153
154
|
# File 'lib/git_storyid.rb', line 150
def self.build
load_config
ensure_full_config
TRACKER_CONFIG[engine][:class].new(@config)
end
|
.engine ⇒ Object
162
163
164
165
|
# File 'lib/git_storyid.rb', line 162
def engine
e = @config[:engine]
e ? e.to_sym : nil
end
|
.ensure_full_config ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/git_storyid.rb', line 167
def ensure_full_config
@config[:engine] = read_configuration_value("Engine (pivotal/jira)") unless engine
tracker_config = TRACKER_CONFIG[engine]
return if tracker_config && @config.keys.sort == (tracker_config[:options].keys + [:engine]).sort
tracker_config[:options].each do |key, label|
@config[key] = read_configuration_value(label, key == :password)
end
File.open(project_config_path, "w") do |file|
file.write YAML.dump(@config)
end
output "Writing config to #{project_config_path}"
end
|
.find_project_config ⇒ Object
207
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/git_storyid.rb', line 207
def find_project_config
dirs = File.split(Dir.pwd)
until dirs.empty? || File.exists?(File.join(dirs, FILENAME))
dirs.pop
end
unless dirs.empty?
File.join(dirs, FILENAME)
else
File.join(Dir.pwd, FILENAME)
end
end
|
.load_config ⇒ Object
158
159
160
|
# File 'lib/git_storyid.rb', line 158
def load_config
@config ||= load_config_from
end
|
.load_config_from ⇒ Object
195
196
197
198
199
200
201
202
|
# File 'lib/git_storyid.rb', line 195
def load_config_from
return {} unless project_config_path
if File.exists?(project_config_path)
YAML.load(File.read(project_config_path)) || {}
else
{}
end
end
|
.output(message) ⇒ Object
235
236
237
|
# File 'lib/git_storyid.rb', line 235
def self.output(message)
GitStoryid.output(message)
end
|
.project_config_path ⇒ Object
204
205
206
|
# File 'lib/git_storyid.rb', line 204
def project_config_path
@project_config_path ||= find_project_config
end
|
.read_configuration_value(label, hidden = false) ⇒ Object
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/git_storyid.rb', line 183
def read_configuration_value(label, hidden = false)
label = "#{label}: "
if hidden
print label
password = STDIN.noecho(&:gets).chomp
puts ''
password
else
Readline.readline(label, true)
end
end
|
Instance Method Details
#all_stories ⇒ Object
225
226
227
228
229
|
# File 'lib/git_storyid.rb', line 225
def all_stories
@all_stories ||= fetch_all_stories.map do |story|
serialize_issue(story)
end
end
|
#reset ⇒ Object
231
232
233
|
# File 'lib/git_storyid.rb', line 231
def reset
@all_stories = nil
end
|