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.
-
#remotes ⇒ Object
Returns the value of attribute remotes.
Class Method Summary collapse
- .branches_from_hash(hash) ⇒ Object
- .fetch(remotes, config = nil) ⇒ Object
- .from_hash(remotes, hash) ⇒ Object
Instance Method Summary collapse
- #add_story(remote, ref, story_id) ⇒ Object
- #add_to_merge(remote, ref) ⇒ Object
- #each ⇒ Object
- #failures ⇒ Object
- #fetch ⇒ Object
- #get(remote_url, ref) ⇒ Object
-
#initialize(remotes, config = nil) ⇒ Collection
constructor
A new instance of Collection.
- #mark_deleted(branch) ⇒ Object
- #mark_failure(branch, conflict_sha = nil) ⇒ Object
- #mark_success(branch) ⇒ Object
- #mergeable ⇒ Object
- #remove_from_merge(remote, ref) ⇒ Object
- #reverse_merge(old) ⇒ Object
- #set_resolutions(branch, resolutions) ⇒ Object
- #to_a ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
Constructor Details
#initialize(remotes, config = nil) ⇒ Collection
Returns a new instance of Collection.
11 12 13 14 15 16 17 18 19 |
# File 'lib/flash_flow/data/collection.rb', line 11 def initialize(remotes, config=nil) @remotes = remotes @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.
9 10 11 |
# File 'lib/flash_flow/data/collection.rb', line 9 def branches @branches end |
#remotes ⇒ Object
Returns the value of attribute remotes.
9 10 11 |
# File 'lib/flash_flow/data/collection.rb', line 9 def remotes @remotes end |
Class Method Details
.branches_from_hash(hash) ⇒ Object
33 34 35 36 37 |
# File 'lib/flash_flow/data/collection.rb', line 33 def self.branches_from_hash(hash) hash.each do |key, val| hash[key] = val.is_a?(Branch) ? val : Branch.from_hash(val) end end |
.fetch(remotes, config = nil) ⇒ Object
21 22 23 24 25 |
# File 'lib/flash_flow/data/collection.rb', line 21 def self.fetch(remotes, config=nil) collection = new(remotes, config) collection.fetch collection end |
.from_hash(remotes, hash) ⇒ Object
27 28 29 30 31 |
# File 'lib/flash_flow/data/collection.rb', line 27 def self.from_hash(remotes, hash) collection = new(remotes) collection.branches = branches_from_hash(hash.dup) collection end |
Instance Method Details
#add_story(remote, ref, story_id) ⇒ Object
137 138 139 140 141 142 143 144 |
# File 'lib/flash_flow/data/collection.rb', line 137 def add_story(remote, ref, story_id) branch = get(url_from_remote(remote), 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(remote, ref) ⇒ Object
103 104 105 106 107 |
# File 'lib/flash_flow/data/collection.rb', line 103 def add_to_merge(remote, ref) branch = record(remote, nil, ref) @collection_instance.add_to_merge(branch) if @collection_instance.respond_to?(:add_to_merge) branch end |
#each ⇒ Object
83 84 85 |
# File 'lib/flash_flow/data/collection.rb', line 83 def each to_a.each end |
#failures ⇒ Object
91 92 93 |
# File 'lib/flash_flow/data/collection.rb', line 91 def failures @branches.select { |_, v| v.fail? } end |
#fetch ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/flash_flow/data/collection.rb', line 95 def fetch return unless @collection_instance.respond_to?(:fetch) @collection_instance.fetch.each do |b| update_or_add(b) end end |
#get(remote_url, ref) ⇒ Object
39 40 41 |
# File 'lib/flash_flow/data/collection.rb', line 39 def get(remote_url, ref) @branches[key(remote_url, ref)] end |
#mark_deleted(branch) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/flash_flow/data/collection.rb', line 123 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
116 117 118 119 120 121 |
# File 'lib/flash_flow/data/collection.rb', line 116 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
130 131 132 133 134 135 |
# File 'lib/flash_flow/data/collection.rb', line 130 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
87 88 89 |
# File 'lib/flash_flow/data/collection.rb', line 87 def mergeable to_a.select { |branch| branch.success? || branch.fail? || branch.unknown? } end |
#remove_from_merge(remote, ref) ⇒ Object
109 110 111 112 113 114 |
# File 'lib/flash_flow/data/collection.rb', line 109 def remove_from_merge(remote, ref) branch = record(remote, nil, ref) branch.removed! @collection_instance.remove_from_merge(branch) if @collection_instance.respond_to?(:remove_from_merge) branch end |
#reverse_merge(old) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/flash_flow/data/collection.rb', line 52 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 = branch.resolutions.to_h.merge(info.resolutions.to_h) branch.stories = info.stories.to_a | merged_branches[full_ref].stories.to_a 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(remotes, merged_branches) end |
#set_resolutions(branch, resolutions) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/flash_flow/data/collection.rb', line 146 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 |
#to_a ⇒ Object
79 80 81 |
# File 'lib/flash_flow/data/collection.rb', line 79 def to_a @branches.values end |
#to_hash ⇒ Object Also known as: to_h
43 44 45 46 47 48 49 |
# File 'lib/flash_flow/data/collection.rb', line 43 def to_hash {}.tap do |hash| @branches.each do |key, val| hash[key] = val.to_hash end end end |