Class: Slurper
- Inherits:
-
Object
- Object
- Slurper
- Defined in:
- lib/slurper.rb
Constant Summary collapse
- GLOBAL_STORY_ATTRIBUTES =
['project']
Instance Attribute Summary collapse
-
#handlers ⇒ Object
Returns the value of attribute handlers.
-
#stories ⇒ Object
Returns the value of attribute stories.
-
#story_file ⇒ Object
Returns the value of attribute story_file.
Class Method Summary collapse
- .dump(config_file, filter, handlers, reverse) ⇒ Object
- .load_config(config_file) ⇒ Object
- .load_stories(story_file, defaults = {}) ⇒ Object
- .slurp(story_file, config_file, handlers, reverse) ⇒ Object
Instance Method Summary collapse
- #create_stories ⇒ Object
- #dump_stories(filter) ⇒ Object
-
#initialize(config, stories = []) ⇒ Slurper
constructor
A new instance of Slurper.
Constructor Details
#initialize(config, stories = []) ⇒ Slurper
Returns a new instance of Slurper.
28 29 30 31 32 |
# File 'lib/slurper.rb', line 28 def initialize(config, stories=[]) @config = config @stories = stories @handlers = [] end |
Instance Attribute Details
#handlers ⇒ Object
Returns the value of attribute handlers.
8 9 10 |
# File 'lib/slurper.rb', line 8 def handlers @handlers end |
#stories ⇒ Object
Returns the value of attribute stories.
8 9 10 |
# File 'lib/slurper.rb', line 8 def stories @stories end |
#story_file ⇒ Object
Returns the value of attribute story_file.
8 9 10 |
# File 'lib/slurper.rb', line 8 def story_file @story_file end |
Class Method Details
.dump(config_file, filter, handlers, reverse) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/slurper.rb', line 10 def self.dump(config_file, filter, handlers, reverse) config = self.load_config(config_file) slurper = new(config) slurper.handlers = handlers slurper.dump_stories(filter) end |
.load_config(config_file) ⇒ Object
51 52 53 |
# File 'lib/slurper.rb', line 51 def self.load_config(config_file) YAML.load_file(config_file) end |
.load_stories(story_file, defaults = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/slurper.rb', line 34 def self.load_stories(story_file, defaults = {}) stories = [] yamlize_story_file(story_file).each do |story| begin story_hash = YAML.load(story) stories << story_hash if story_hash.is_a?(Hash) rescue puts 'Error encountered when trying to parse the following story' puts '-' * 10 puts story puts '-' * 10 return [] end end stories.map { |story_hash| YamlStory.new(story_hash, defaults) } end |
.slurp(story_file, config_file, handlers, reverse) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/slurper.rb', line 17 def self.slurp(story_file, config_file, handlers, reverse) config = self.load_config(config_file) stories = self.load_stories(story_file, config.select {|k, _| GLOBAL_STORY_ATTRIBUTES.include?(k)}) stories.reverse! if reverse slurper = new(config, stories) slurper.handlers = handlers slurper.create_stories end |
Instance Method Details
#create_stories ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/slurper.rb', line 61 def create_stories puts "Preparing to slurp #{stories.size} stories into #{handler.class.name}..." @stories.each_with_index do |story, index| puts "#{index+1}. #{story.name}" begin handler.handle(story) do |status, | if status puts "Success: #{}" else puts "Failed: #{}" end end rescue Exception => ex puts "Failed: #{ex.}" end end end |
#dump_stories(filter) ⇒ Object
55 56 57 58 59 |
# File 'lib/slurper.rb', line 55 def dump_stories(filter) handler.dump(filter) do |story| puts story.to_yaml end end |