Class: Pickler

Inherits:
Object
  • 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.



26
27
28
29
30
31
32
33
34
35
# File 'lib/pickler.rb', line 26

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

#directoryObject (readonly)

Returns the value of attribute directory.



24
25
26
# File 'lib/pickler.rb', line 24

def directory
  @directory
end

Class Method Details

.configObject



12
13
14
15
16
17
18
# File 'lib/pickler.rb', line 12

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



20
21
22
# File 'lib/pickler.rb', line 20

def self.run(argv)
  Runner.new(argv).run
end

Instance Method Details

#configObject



45
46
47
48
# File 'lib/pickler.rb', line 45

def config
  @config ||= File.exist?(config_file) && YAML.load_file(config_file) || {}
  self.class.config.merge(@config)
end

#config_fileObject



41
42
43
# File 'lib/pickler.rb', line 41

def config_file
  features_path('tracker.yml')
end

#deliver_all_finished_storiesObject



81
82
83
# File 'lib/pickler.rb', line 81

def deliver_all_finished_stories
  project.deliver_all_finished_stories
end

#feature(string) ⇒ Object



128
129
130
# File 'lib/pickler.rb', line 128

def feature(string)
  string.kind_of?(Feature) ? string : Feature.new(self,string)
end

#features_path(*subdirs) ⇒ Object



37
38
39
# File 'lib/pickler.rb', line 37

def features_path(*subdirs)
  File.join(@directory,'features',*subdirs)
end

#formatObject



112
113
114
# File 'lib/pickler.rb', line 112

def format
  (config['format'] || :tag).to_sym
end

#iteration_lengthObject



69
70
71
# File 'lib/pickler.rb', line 69

def iteration_length
  project.iteration_length
end

#local_featuresObject



116
117
118
# File 'lib/pickler.rb', line 116

def local_features
  Dir[features_path('**','*.feature')].map {|f|feature(f)}.select {|f|f.pushable?}
end

#nameObject



65
66
67
# File 'lib/pickler.rb', line 65

def name
  project.name
end

#new_story(attributes = {}, &block) ⇒ Object



54
55
56
57
58
59
# File 'lib/pickler.rb', line 54

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



85
86
87
88
# File 'lib/pickler.rb', line 85

def parse(story)
  require 'cucumber'
  Cucumber::FeatureFile.new(story.url, story.to_s).parse(:lang => @lang)
end

#point_scaleObject



73
74
75
# File 'lib/pickler.rb', line 73

def point_scale
  project.point_scale
end

#projectObject



94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/pickler.rb', line 94

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_idObject



90
91
92
# File 'lib/pickler.rb', line 90

def project_id
  config["project_id"] || (self.class.config["projects"]||{})[File.basename(@directory)]
end

#real_nameObject



50
51
52
# File 'lib/pickler.rb', line 50

def real_name
  config["real_name"] || (require 'etc'; Etc.getpwuid.gecos.split(',').first)
end

#scenario_features(excluded_states = %w(unscheduled unstarted))) ⇒ Object



120
121
122
123
124
125
126
# File 'lib/pickler.rb', line 120

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_wordObject



107
108
109
110
# File 'lib/pickler.rb', line 107

def scenario_word
  require 'cucumber'
  Cucumber::LANGUAGES[@lang]['scenario']
end

#stories(*args) ⇒ Object



61
62
63
# File 'lib/pickler.rb', line 61

def stories(*args)
  project.stories(*args)
end

#story(string) ⇒ Object



132
133
134
# File 'lib/pickler.rb', line 132

def story(string)
  feature(string).story
end

#week_start_dayObject



77
78
79
# File 'lib/pickler.rb', line 77

def week_start_day
  project.week_start_day
end