Class: FlashFlow::Data::Collection
- Inherits:
-
Object
- Object
- FlashFlow::Data::Collection
- Defined in:
- lib/flash_flow/data/collection.rb
Instance Attribute Summary collapse
-
#branches ⇒ Object
Returns the value of attribute branches.
Class Method Summary collapse
- .branches_from_hash(hash) ⇒ Object
- .fetch(config = nil) ⇒ Object
- .from_hash(hash, collection_instance = nil) ⇒ Object
- .key(ref) ⇒ Object
Instance Method Summary collapse
- #add_story(ref, story_id) ⇒ Object
- #add_to_merge(ref) ⇒ Object
- #branch_link(branch) ⇒ Object
- #can_ship?(branch) ⇒ Boolean
- #code_reviewed?(branch) ⇒ Boolean
- #current_branches ⇒ Object
- #each ⇒ Object
- #failures ⇒ Object
- #fetch ⇒ Object
- #get(ref) ⇒ Object
-
#initialize(config = nil) ⇒ Collection
constructor
A new instance of Collection.
- #mark_all_as_current ⇒ Object
- #mark_deleted(branch) ⇒ Object
- #mark_failure(branch, conflict_sha = nil) ⇒ Object
- #mark_success(branch) ⇒ Object
- #mergeable ⇒ Object
- #removals ⇒ Object
- #remove_from_merge(ref) ⇒ Object
- #reverse_merge(old) ⇒ Object
- #set_resolutions(branch, resolutions) ⇒ Object
- #successes ⇒ Object
- #to_a ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(config = nil) ⇒ Collection
Returns a new instance of Collection.
12 13 14 15 16 17 18 19 |
# File 'lib/flash_flow/data/collection.rb', line 12 def initialize(config=nil) @branches = {} if config && config['class'] && config['class']['name'] collection_class = Object.const_get(config['class']['name']) @collection_instance = collection_class.new(config['class']) end end |
Instance Attribute Details
#branches ⇒ Object
Returns the value of attribute branches.
10 11 12 |
# File 'lib/flash_flow/data/collection.rb', line 10 def branches @branches end |
Class Method Details
.branches_from_hash(hash) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/flash_flow/data/collection.rb', line 34 def self.branches_from_hash(hash) {}.tap do |new_branches| hash.each do |_, val| branch = val.is_a?(Branch) ? val : Branch.from_hash(val) new_branches[branch.ref] = branch end end end |
.fetch(config = nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/flash_flow/data/collection.rb', line 21 def self.fetch(config=nil) collection = new(config) collection.fetch collection end |
.from_hash(hash, collection_instance = nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/flash_flow/data/collection.rb', line 27 def self.from_hash(hash, collection_instance=nil) collection = new collection.branches = branches_from_hash(hash) collection.instance_variable_set(:@collection_instance, collection_instance) collection end |
.key(ref) ⇒ Object
43 44 45 |
# File 'lib/flash_flow/data/collection.rb', line 43 def self.key(ref) ref end |
Instance Method Details
#add_story(ref, story_id) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/flash_flow/data/collection.rb', line 166 def add_story(ref, story_id) branch = get(ref) branch.stories ||= [] branch.stories << story_id @collection_instance.add_story(branch, story_id) if @collection_instance.respond_to?(:add_story) branch end |
#add_to_merge(ref) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/flash_flow/data/collection.rb', line 130 def add_to_merge(ref) branch = record(ref) branch.current_record = true @collection_instance.add_to_merge(branch) if @collection_instance.respond_to?(:add_to_merge) branch end |
#branch_link(branch) ⇒ Object
183 184 185 |
# File 'lib/flash_flow/data/collection.rb', line 183 def branch_link(branch) @collection_instance.branch_link(branch) if @collection_instance.respond_to?(:branch_link) end |
#can_ship?(branch) ⇒ Boolean
179 180 181 |
# File 'lib/flash_flow/data/collection.rb', line 179 def can_ship?(branch) @collection_instance.respond_to?(:can_ship?) ? @collection_instance.can_ship?(branch) : true end |
#code_reviewed?(branch) ⇒ Boolean
175 176 177 |
# File 'lib/flash_flow/data/collection.rb', line 175 def code_reviewed?(branch) @collection_instance.respond_to?(:code_reviewed?) ? @collection_instance.code_reviewed?(branch) : true end |
#current_branches ⇒ Object
96 97 98 |
# File 'lib/flash_flow/data/collection.rb', line 96 def current_branches to_a.select { |branch| branch.current_record } end |
#each ⇒ Object
92 93 94 |
# File 'lib/flash_flow/data/collection.rb', line 92 def each to_a.each end |
#failures ⇒ Object
104 105 106 |
# File 'lib/flash_flow/data/collection.rb', line 104 def failures current_branches.select { |branch| branch.fail? } end |
#fetch ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/flash_flow/data/collection.rb', line 116 def fetch return unless @collection_instance.respond_to?(:fetch) @collection_instance.fetch.each do |b| update_or_add(b) end end |
#get(ref) ⇒ Object
47 48 49 |
# File 'lib/flash_flow/data/collection.rb', line 47 def get(ref) @branches[key(ref)] end |
#mark_all_as_current ⇒ Object
124 125 126 127 128 |
# File 'lib/flash_flow/data/collection.rb', line 124 def mark_all_as_current @branches.each do |_, branch| branch.current_record = true end end |
#mark_deleted(branch) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/flash_flow/data/collection.rb', line 152 def mark_deleted(branch) update_or_add(branch) branch.deleted! @collection_instance.mark_deleted(branch) if @collection_instance.respond_to?(:mark_deleted) branch end |
#mark_failure(branch, conflict_sha = nil) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/flash_flow/data/collection.rb', line 145 def mark_failure(branch, conflict_sha=nil) update_or_add(branch) branch.fail!(conflict_sha) @collection_instance.mark_failure(branch) if @collection_instance.respond_to?(:mark_failure) branch end |
#mark_success(branch) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/flash_flow/data/collection.rb', line 159 def mark_success(branch) update_or_add(branch) branch.success! @collection_instance.mark_success(branch) if @collection_instance.respond_to?(:mark_success) branch end |
#mergeable ⇒ Object
100 101 102 |
# File 'lib/flash_flow/data/collection.rb', line 100 def mergeable current_branches.select { |branch| (branch.success? || branch.fail? || branch.unknown?) } end |
#removals ⇒ Object
112 113 114 |
# File 'lib/flash_flow/data/collection.rb', line 112 def removals to_a.select { |branch| branch.removed? } end |
#remove_from_merge(ref) ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/flash_flow/data/collection.rb', line 137 def remove_from_merge(ref) branch = record(ref) branch.current_record = true branch.removed! @collection_instance.remove_from_merge(branch) if @collection_instance.respond_to?(:remove_from_merge) branch end |
#reverse_merge(old) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/flash_flow/data/collection.rb', line 60 def reverse_merge(old) merged_branches = @branches.dup merged_branches.each do |_, info| info.updated_at = Time.now info.created_at ||= Time.now end old.branches.each do |full_ref, info| if merged_branches.has_key?(full_ref) branch = merged_branches[full_ref] branch.created_at = info.created_at branch.resolutions = info.resolutions.to_h.merge(branch.resolutions.to_h) branch.stories = info.stories.to_a | merged_branches[full_ref].stories.to_a branch.merge_order ||= info.merge_order if branch.fail? branch.conflict_sha ||= info.conflict_sha end else merged_branches[full_ref] = info merged_branches[full_ref].status = nil end end self.class.from_hash(merged_branches, @collection_instance) end |
#set_resolutions(branch, resolutions) ⇒ Object
187 188 189 190 191 192 |
# File 'lib/flash_flow/data/collection.rb', line 187 def set_resolutions(branch, resolutions) update_or_add(branch) branch.set_resolutions(resolutions) @collection_instance.set_resolutions(branch) if @collection_instance.respond_to?(:set_resolutions) branch end |
#successes ⇒ Object
108 109 110 |
# File 'lib/flash_flow/data/collection.rb', line 108 def successes current_branches.select { |branch| branch.success? } end |
#to_a ⇒ Object
88 89 90 |
# File 'lib/flash_flow/data/collection.rb', line 88 def to_a @branches.values end |
#to_hash ⇒ Object Also known as: to_h
51 52 53 54 55 56 57 |
# File 'lib/flash_flow/data/collection.rb', line 51 def to_hash {}.tap do |hash| @branches.each do |key, val| hash[key] = val.to_hash end end end |