Class: JIRADiff::Stories

Inherits:
Object
  • Object
show all
Defined in:
lib/jira_diff/stories.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#branchesObject

Returns the value of attribute branches.



17
18
19
# File 'lib/jira_diff/stories.rb', line 17

def branches
  @branches
end

#directoryObject 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

#includesObject

Returns the value of attribute includes.



18
19
20
# File 'lib/jira_diff/stories.rb', line 18

def includes
  @includes
end

#storiesObject (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

#diffObject



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

#eachObject



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

Raises:

  • (ArgumentError)


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

#masterObject



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

#shasObject



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

#sourceObject



28
29
30
# File 'lib/jira_diff/stories.rb', line 28

def source
  @branches[1, @branches.size]
end

#source_storiesObject



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