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.
11 12 13 14 15 16 17 18 |
# File 'lib/flash_flow/data/collection.rb', line 11 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.
9 10 11 |
# File 'lib/flash_flow/data/collection.rb', line 9 def branches @branches end |
Class Method Details
.branches_from_hash(hash) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/flash_flow/data/collection.rb', line 33 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
20 21 22 23 24 |
# File 'lib/flash_flow/data/collection.rb', line 20 def self.fetch(config=nil) collection = new(config) collection.fetch collection end |
.from_hash(hash, collection_instance = nil) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/flash_flow/data/collection.rb', line 26 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
42 43 44 |
# File 'lib/flash_flow/data/collection.rb', line 42 def self.key(ref) ref end |
Instance Method Details
#add_story(ref, story_id) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/flash_flow/data/collection.rb', line 165 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
129 130 131 132 133 134 |
# File 'lib/flash_flow/data/collection.rb', line 129 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
182 183 184 |
# File 'lib/flash_flow/data/collection.rb', line 182 def branch_link(branch) @collection_instance.branch_link(branch) if @collection_instance.respond_to?(:branch_link) end |
#can_ship?(branch) ⇒ Boolean
178 179 180 |
# File 'lib/flash_flow/data/collection.rb', line 178 def can_ship?(branch) @collection_instance.respond_to?(:can_ship?) ? @collection_instance.can_ship?(branch) : true end |
#code_reviewed?(branch) ⇒ Boolean
174 175 176 |
# File 'lib/flash_flow/data/collection.rb', line 174 def code_reviewed?(branch) @collection_instance.respond_to?(:code_reviewed?) ? @collection_instance.code_reviewed?(branch) : true end |
#current_branches ⇒ Object
95 96 97 |
# File 'lib/flash_flow/data/collection.rb', line 95 def current_branches to_a.select { |branch| branch.current_record } end |
#each ⇒ Object
91 92 93 |
# File 'lib/flash_flow/data/collection.rb', line 91 def each to_a.each end |
#failures ⇒ Object
103 104 105 |
# File 'lib/flash_flow/data/collection.rb', line 103 def failures current_branches.select { |branch| branch.fail? } end |
#fetch ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/flash_flow/data/collection.rb', line 115 def fetch return unless @collection_instance.respond_to?(:fetch) @collection_instance.fetch.each do |b| update_or_add(b) end end |
#get(ref) ⇒ Object
46 47 48 |
# File 'lib/flash_flow/data/collection.rb', line 46 def get(ref) @branches[key(ref)] end |
#mark_all_as_current ⇒ Object
123 124 125 126 127 |
# File 'lib/flash_flow/data/collection.rb', line 123 def mark_all_as_current @branches.each do |_, branch| branch.current_record = true end end |
#mark_deleted(branch) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/flash_flow/data/collection.rb', line 151 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
144 145 146 147 148 149 |
# File 'lib/flash_flow/data/collection.rb', line 144 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
158 159 160 161 162 163 |
# File 'lib/flash_flow/data/collection.rb', line 158 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
99 100 101 |
# File 'lib/flash_flow/data/collection.rb', line 99 def mergeable current_branches.select { |branch| (branch.success? || branch.fail? || branch.unknown?) } end |
#removals ⇒ Object
111 112 113 |
# File 'lib/flash_flow/data/collection.rb', line 111 def removals to_a.select { |branch| branch.removed? } end |
#remove_from_merge(ref) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/flash_flow/data/collection.rb', line 136 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
59 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 |
# File 'lib/flash_flow/data/collection.rb', line 59 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
186 187 188 189 190 191 |
# File 'lib/flash_flow/data/collection.rb', line 186 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
107 108 109 |
# File 'lib/flash_flow/data/collection.rb', line 107 def successes current_branches.select { |branch| branch.success? } end |
#to_a ⇒ Object
87 88 89 |
# File 'lib/flash_flow/data/collection.rb', line 87 def to_a @branches.values end |
#to_hash ⇒ Object Also known as: to_h
50 51 52 53 54 55 56 |
# File 'lib/flash_flow/data/collection.rb', line 50 def to_hash {}.tap do |hash| @branches.each do |key, val| hash[key] = val.to_hash end end end |