Class: Pickler
- Inherits:
-
Object
show all
- Defined in:
- lib/pickler.rb,
lib/pickler/runner.rb,
lib/pickler/feature.rb,
lib/pickler/tracker.rb,
lib/pickler/tracker/note.rb,
lib/pickler/tracker/story.rb,
lib/pickler/tracker/project.rb,
lib/pickler/tracker/iteration.rb
Defined Under Namespace
Classes: Error, Feature, Runner, Tracker
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(path = '.') ⇒ Pickler
Returns a new instance of Pickler.
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/pickler.rb', line 28
def initialize(path = '.')
@lang = 'en'
@directory = File.expand_path(path)
until File.directory?(File.join(@directory,'features'))
if @directory == File.dirname(@directory)
raise Error, 'Project not found. Make sure you have a features/ directory.', caller
end
@directory = File.dirname(@directory)
end
end
|
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
26
27
28
|
# File 'lib/pickler.rb', line 26
def directory
@directory
end
|
Class Method Details
.config ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/pickler.rb', line 14
def self.config
@config ||= {'api_token' => ENV["TRACKER_API_TOKEN"]}.merge(
if File.exist?(path = File.expand_path('~/.tracker.yml'))
YAML.load_file(path)
end || {}
)
end
|
.run(argv) ⇒ Object
22
23
24
|
# File 'lib/pickler.rb', line 22
def self.run(argv)
Runner.new(argv).run
end
|
Instance Method Details
#config ⇒ Object
47
48
49
50
|
# File 'lib/pickler.rb', line 47
def config
@config ||= File.exist?(config_file) && YAML.load_file(config_file) || {}
self.class.config.merge(@config)
end
|
#config_file ⇒ Object
43
44
45
|
# File 'lib/pickler.rb', line 43
def config_file
features_path('tracker.yml')
end
|
#deliver_all_finished_stories ⇒ Object
83
84
85
|
# File 'lib/pickler.rb', line 83
def deliver_all_finished_stories
project.deliver_all_finished_stories
end
|
#feature(string) ⇒ Object
130
131
132
|
# File 'lib/pickler.rb', line 130
def feature(string)
string.kind_of?(Feature) ? string : Feature.new(self,string)
end
|
#features_path(*subdirs) ⇒ Object
39
40
41
|
# File 'lib/pickler.rb', line 39
def features_path(*subdirs)
File.join(@directory,'features',*subdirs)
end
|
114
115
116
|
# File 'lib/pickler.rb', line 114
def format
(config['format'] || :tag).to_sym
end
|
#iteration_length ⇒ Object
71
72
73
|
# File 'lib/pickler.rb', line 71
def iteration_length
project.iteration_length
end
|
#local_features ⇒ Object
118
119
120
|
# File 'lib/pickler.rb', line 118
def local_features
Dir[features_path('**','*.feature')].map {|f|feature(f)}.select {|f|f.pushable?}
end
|
#name ⇒ Object
67
68
69
|
# File 'lib/pickler.rb', line 67
def name
project.name
end
|
#new_story(attributes = {}, &block) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/pickler.rb', line 56
def new_story(attributes = {}, &block)
attributes = attributes.inject('requested_by' => real_name) do |h,(k,v)|
h.update(k.to_s => v)
end
project.new_story(attributes, &block)
end
|
#parse(story) ⇒ Object
87
88
89
90
|
# File 'lib/pickler.rb', line 87
def parse(story)
require 'cucumber'
Cucumber::FeatureFile.new(story.url, story.to_s).parse(Cucumber::StepMother.new, :lang => @lang)
end
|
#point_scale ⇒ Object
75
76
77
|
# File 'lib/pickler.rb', line 75
def point_scale
project.point_scale
end
|
#project ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/pickler.rb', line 96
def project
@project ||= Dir.chdir(@directory) do
unless token = config['api_token']
raise Error, 'echo api_token: ... > ~/.tracker.yml'
end
unless id = project_id
raise Error, 'echo project_id: ... > features/tracker.yml'
end
ssl = config['ssl']
Tracker.new(token, ssl).project(id)
end
end
|
#project_id ⇒ Object
92
93
94
|
# File 'lib/pickler.rb', line 92
def project_id
config["project_id"] || (self.class.config["projects"]||{})[File.basename(@directory)]
end
|
#real_name ⇒ Object
52
53
54
|
# File 'lib/pickler.rb', line 52
def real_name
config["real_name"] || (require 'etc'; Etc.getpwuid.gecos.split(',').first)
end
|
#scenario_features(excluded_states = %w(unscheduled unstarted))) ⇒ Object
122
123
124
125
126
127
128
|
# File 'lib/pickler.rb', line 122
def scenario_features(excluded_states = %w(unscheduled unstarted))
project.stories(scenario_word, :includedone => true).reject do |s|
Array(excluded_states).map {|state| state.to_s}.include?(s.current_state)
end.select do |s|
s.to_s =~ /^\s*#{Regexp.escape(scenario_word)}:/ && parse(s) rescue false
end
end
|
#scenario_word ⇒ Object
109
110
111
112
|
# File 'lib/pickler.rb', line 109
def scenario_word
require 'cucumber'
Cucumber::LANGUAGES[@lang]['scenario']
end
|
#stories(*args) ⇒ Object
63
64
65
|
# File 'lib/pickler.rb', line 63
def stories(*args)
project.stories(*args)
end
|
#story(string) ⇒ Object
134
135
136
|
# File 'lib/pickler.rb', line 134
def story(string)
feature(string).story
end
|
#week_start_day ⇒ Object
79
80
81
|
# File 'lib/pickler.rb', line 79
def week_start_day
project.week_start_day
end
|