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.
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/pickler.rb', line 27
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.
25
26
27
|
# File 'lib/pickler.rb', line 25
def directory
@directory
end
|
Class Method Details
.config ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/pickler.rb', line 13
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
21
22
23
|
# File 'lib/pickler.rb', line 21
def self.run(argv)
Runner.new(argv).run
end
|
Instance Method Details
#config ⇒ Object
46
47
48
49
|
# File 'lib/pickler.rb', line 46
def config
@config ||= File.exist?(config_file) && YAML.load_file(config_file) || {}
self.class.config.merge(@config)
end
|
#config_file ⇒ Object
42
43
44
|
# File 'lib/pickler.rb', line 42
def config_file
features_path('tracker.yml')
end
|
#deliver_all_finished_stories ⇒ Object
82
83
84
|
# File 'lib/pickler.rb', line 82
def deliver_all_finished_stories
project.deliver_all_finished_stories
end
|
#feature(string) ⇒ Object
129
130
131
|
# File 'lib/pickler.rb', line 129
def feature(string)
string.kind_of?(Feature) ? string : Feature.new(self,string)
end
|
#features_path(*subdirs) ⇒ Object
38
39
40
|
# File 'lib/pickler.rb', line 38
def features_path(*subdirs)
File.join(@directory,'features',*subdirs)
end
|
113
114
115
|
# File 'lib/pickler.rb', line 113
def format
(config['format'] || :tag).to_sym
end
|
#iteration_length ⇒ Object
70
71
72
|
# File 'lib/pickler.rb', line 70
def iteration_length
project.iteration_length
end
|
#local_features ⇒ Object
117
118
119
|
# File 'lib/pickler.rb', line 117
def local_features
Dir[features_path('**','*.feature')].map {|f|feature(f)}.select {|f|f.pushable?}
end
|
#name ⇒ Object
66
67
68
|
# File 'lib/pickler.rb', line 66
def name
project.name
end
|
#new_story(attributes = {}, &block) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/pickler.rb', line 55
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
86
87
88
89
|
# File 'lib/pickler.rb', line 86
def parse(story)
require 'cucumber'
Cucumber::FeatureFile.new(story.url, story.to_s).parse(Cucumber::StepMother.new, :lang => @lang)
end
|
#point_scale ⇒ Object
74
75
76
|
# File 'lib/pickler.rb', line 74
def point_scale
project.point_scale
end
|
#project ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/pickler.rb', line 95
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
91
92
93
|
# File 'lib/pickler.rb', line 91
def project_id
config["project_id"] || (self.class.config["projects"]||{})[File.basename(@directory)]
end
|
#real_name ⇒ Object
51
52
53
|
# File 'lib/pickler.rb', line 51
def real_name
config["real_name"] || (require 'etc'; Etc.getpwuid.gecos.split(',').first)
end
|
#scenario_features(excluded_states = %w(unscheduled unstarted))) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/pickler.rb', line 121
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
108
109
110
111
|
# File 'lib/pickler.rb', line 108
def scenario_word
require 'cucumber'
Cucumber::LANGUAGES[@lang]['scenario']
end
|
#stories(*args) ⇒ Object
62
63
64
|
# File 'lib/pickler.rb', line 62
def stories(*args)
project.stories(*args)
end
|
#story(string) ⇒ Object
133
134
135
|
# File 'lib/pickler.rb', line 133
def story(string)
feature(string).story
end
|
#week_start_day ⇒ Object
78
79
80
|
# File 'lib/pickler.rb', line 78
def week_start_day
project.week_start_day
end
|