class FlashFlow::Data::Collection
Attributes
branches[RW]
Public Class Methods
branches_from_hash(hash)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/flash_flow/data/collection.rb, line 43 def self.key(ref) ref end
new(config=nil)
click to toggle source
# 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
Public Instance Methods
add_story(ref, story_id)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/flash_flow/data/collection.rb, line 96 def current_branches to_a.select { |branch| branch.current_record } end
each()
click to toggle source
# File lib/flash_flow/data/collection.rb, line 92 def each to_a.each end
failures()
click to toggle source
# File lib/flash_flow/data/collection.rb, line 104 def failures current_branches.select { |branch| branch.fail? } end
fetch()
click to toggle source
# 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)
click to toggle source
# File lib/flash_flow/data/collection.rb, line 47 def get(ref) @branches[key(ref)] end
mark_all_as_current()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/flash_flow/data/collection.rb, line 100 def mergeable current_branches.select { |branch| (branch.success? || branch.fail? || branch.unknown?) } end
removals()
click to toggle source
# File lib/flash_flow/data/collection.rb, line 112 def removals to_a.select { |branch| branch.removed? } end
remove_from_merge(ref)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/flash_flow/data/collection.rb, line 108 def successes current_branches.select { |branch| branch.success? } end
to_a()
click to toggle source
# File lib/flash_flow/data/collection.rb, line 88 def to_a @branches.values end
to_hash()
click to toggle source
# 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
Also aliased as: to_h
Private Instance Methods
key(ref)
click to toggle source
# File lib/flash_flow/data/collection.rb, line 196 def key(ref) self.class.key(ref) end
record(ref)
click to toggle source
# File lib/flash_flow/data/collection.rb, line 205 def record(ref) update_or_add(Branch.new(ref)) end
update_or_add(branch)
click to toggle source
# File lib/flash_flow/data/collection.rb, line 200 def update_or_add(branch) old_branch = @branches[key(branch.ref)] @branches[key(branch.ref)] = old_branch.nil? ? branch : old_branch.merge(branch) end