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.



39
40
41
42
43
44
45
46
47
48
# File 'lib/pickler.rb', line 39

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.



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

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

.hash_to_xml(root, attributes) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pickler.rb', line 20

def self.hash_to_xml(root, attributes)
  require 'cgi'
  xml = "<#{root}>"
  attributes.each do |k,v|
    if v.kind_of?(Hash)
      xml << hash_to_xml(k, v)
    else
      xml << "<#{k}>#{CGI.escapeHTML(v.to_s)}</#{k}>"
    end
  end
  xml << "</#{root}>"
end

.run(argv) ⇒ Object



33
34
35
# File 'lib/pickler.rb', line 33

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

Instance Method Details

#configObject



58
59
60
61
# File 'lib/pickler.rb', line 58

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

#config_fileObject



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

def config_file
  features_path('tracker.yml')
end

#deliver_all_finished_storiesObject



94
95
96
# File 'lib/pickler.rb', line 94

def deliver_all_finished_stories
  project.deliver_all_finished_stories
end

#feature(string) ⇒ Object



139
140
141
# File 'lib/pickler.rb', line 139

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

#features_path(*subdirs) ⇒ Object



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

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

#formatObject



123
124
125
# File 'lib/pickler.rb', line 123

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

#iteration_lengthObject



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

def iteration_length
  project.iteration_length
end

#local_featuresObject



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

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

#nameObject



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

def name
  project.name
end

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



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

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

#point_scaleObject



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

def point_scale
  project.point_scale
end

#projectObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/pickler.rb', line 102

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



98
99
100
# File 'lib/pickler.rb', line 98

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

#real_nameObject



63
64
65
# File 'lib/pickler.rb', line 63

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

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



131
132
133
134
135
136
137
# File 'lib/pickler.rb', line 131

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)}:/
  end
end

#scenario_wordObject



115
116
117
118
119
120
121
# File 'lib/pickler.rb', line 115

def scenario_word
  if @lang == 'en'
    'Scenario'
  else
    raise Error, 'Sorry, no internationalization support (yet)'
  end
end

#stories(*args) ⇒ Object



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

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

#story(string) ⇒ Object



143
144
145
# File 'lib/pickler.rb', line 143

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

#week_start_dayObject



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

def week_start_day
  project.week_start_day
end