Class: JIRADiff::Stories
- Inherits:
-
Object
- Object
- JIRADiff::Stories
- Defined in:
- lib/jira_diff/stories.rb
Instance Attribute Summary collapse
-
#branches ⇒ Object
Returns the value of attribute branches.
-
#directory ⇒ Object
(also: #dir)
Returns the value of attribute directory.
-
#includes ⇒ Object
Returns the value of attribute includes.
-
#stories ⇒ Object
readonly
Returns the value of attribute stories.
Instance Method Summary collapse
- #add_include(story) ⇒ Object
- #add_story(branch, story) ⇒ Object
- #diff ⇒ Object
- #each ⇒ Object
- #find(branch, sha) ⇒ Object
-
#initialize(opts = Options.defaults) ⇒ Stories
constructor
A new instance of Stories.
- #master ⇒ Object
- #master=(new_master) ⇒ Object
- #shas ⇒ Object
- #source ⇒ Object
- #source_stories ⇒ Object
Constructor Details
#initialize(opts = Options.defaults) ⇒ Stories
Returns a new instance of Stories.
7 8 9 10 11 12 13 14 15 |
# File 'lib/jira_diff/stories.rb', line 7 def initialize(opts = Options.defaults) @branches = _get_branches(opts[:master], opts[:source]) @directory = opts[:directory] || '.' @includes = _get_includes(opts.includes) @options = opts @stories = opts[:stories] || {} _get_stories if @stories == {} end |
Instance Attribute Details
#branches ⇒ Object
Returns the value of attribute branches.
17 18 19 |
# File 'lib/jira_diff/stories.rb', line 17 def branches @branches end |
#directory ⇒ Object Also known as: dir
Returns the value of attribute directory.
17 18 19 |
# File 'lib/jira_diff/stories.rb', line 17 def directory @directory end |
#includes ⇒ Object
Returns the value of attribute includes.
18 19 20 |
# File 'lib/jira_diff/stories.rb', line 18 def includes @includes end |
#stories ⇒ Object (readonly)
Returns the value of attribute stories.
18 19 20 |
# File 'lib/jira_diff/stories.rb', line 18 def stories @stories end |
Instance Method Details
#add_include(story) ⇒ Object
32 33 34 |
# File 'lib/jira_diff/stories.rb', line 32 def add_include(story) @includes << story end |
#add_story(branch, story) ⇒ Object
66 67 68 |
# File 'lib/jira_diff/stories.rb', line 66 def add_story(branch, story) (@stories[branch] ||= []).push story end |
#diff ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jira_diff/stories.rb', line 78 def diff stories = [] opts = @options source_stories.each do |story| stories << story unless find(master, story.sha) end opts.source = ['diff'] opts.stories = {'diff' => stories.flatten} Stories.new opts end |
#each ⇒ Object
22 23 24 25 26 |
# File 'lib/jira_diff/stories.rb', line 22 def each @stories.values.each do |stories| stories.each { |story| yield story } end end |
#find(branch, sha) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/jira_diff/stories.rb', line 70 def find(branch, sha) raise ArgumentError, "Invalid environment #{branch}" unless @branches.include?(branch) @stories[branch].each { |story| return true if story.sha == sha } false end |
#master ⇒ Object
40 41 42 |
# File 'lib/jira_diff/stories.rb', line 40 def master @branches[0] end |
#master=(new_master) ⇒ Object
44 45 46 47 48 |
# File 'lib/jira_diff/stories.rb', line 44 def master=(new_master) @stories[master] = [] @branches[0] = new_master _get_stories(new_master) end |
#shas ⇒ Object
50 51 52 53 54 |
# File 'lib/jira_diff/stories.rb', line 50 def shas source.map do |branch| stories[branch].map { |s| s.sha } end.flatten.reverse end |
#source ⇒ Object
28 29 30 |
# File 'lib/jira_diff/stories.rb', line 28 def source @branches[1, @branches.size] end |
#source_stories ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/jira_diff/stories.rb', line 56 def source_stories story_index = {} source.each do |branch| stories[branch].each { |s| story_index[s.sha] = s } end story_index.values end |