Class: FlashFlow::Data::Branch
- Inherits:
-
Object
- Object
- FlashFlow::Data::Branch
- Defined in:
- lib/flash_flow/data/branch.rb
Instance Attribute Summary collapse
-
#conflict_sha ⇒ Object
Returns the value of attribute conflict_sha.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#current_record ⇒ Object
Returns the value of attribute current_record.
-
#merge_order ⇒ Object
Returns the value of attribute merge_order.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#ref ⇒ Object
Returns the value of attribute ref.
-
#remote ⇒ Object
Returns the value of attribute remote.
-
#remote_url ⇒ Object
Returns the value of attribute remote_url.
-
#resolutions ⇒ Object
Returns the value of attribute resolutions.
-
#sha ⇒ Object
Returns the value of attribute sha.
-
#status ⇒ Object
Returns the value of attribute status.
-
#stories ⇒ Object
Returns the value of attribute stories.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_metadata(data) ⇒ Object
- #deleted! ⇒ Object
- #deleted? ⇒ Boolean
- #fail!(conflict_sha = nil) ⇒ Object
- #fail? ⇒ Boolean
-
#initialize(_remote, _remote_url, _ref) ⇒ Branch
constructor
A new instance of Branch.
- #merge(other) ⇒ Object
- #removed! ⇒ Object
- #removed? ⇒ Boolean
- #set_resolutions(_resolutions) ⇒ Object
- #success! ⇒ Object
- #success? ⇒ Boolean
- #to_hash ⇒ Object (also: #to_h)
- #to_json(_) ⇒ Object
- #unknown! ⇒ Object
- #unknown? ⇒ Boolean
Constructor Details
#initialize(_remote, _remote_url, _ref) ⇒ Branch
Returns a new instance of Branch.
10 11 12 13 14 15 16 17 18 |
# File 'lib/flash_flow/data/branch.rb', line 10 def initialize(_remote, _remote_url, _ref) @remote = _remote @remote_url = _remote_url @ref = _ref @resolutions = {} @stories = [] @updated_at = Time.now @created_at = Time.now end |
Instance Attribute Details
#conflict_sha ⇒ Object
Returns the value of attribute conflict_sha.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def conflict_sha @conflict_sha end |
#created_at ⇒ Object
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def created_at @created_at end |
#current_record ⇒ Object
Returns the value of attribute current_record.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def current_record @current_record end |
#merge_order ⇒ Object
Returns the value of attribute merge_order.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def merge_order @merge_order end |
#metadata ⇒ Object
Returns the value of attribute metadata.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def @metadata end |
#ref ⇒ Object
Returns the value of attribute ref.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def ref @ref end |
#remote ⇒ Object
Returns the value of attribute remote.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def remote @remote end |
#remote_url ⇒ Object
Returns the value of attribute remote_url.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def remote_url @remote_url end |
#resolutions ⇒ Object
Returns the value of attribute resolutions.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def resolutions @resolutions end |
#sha ⇒ Object
Returns the value of attribute sha.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def sha @sha end |
#status ⇒ Object
Returns the value of attribute status.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def status @status end |
#stories ⇒ Object
Returns the value of attribute stories.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def stories @stories end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
7 8 9 |
# File 'lib/flash_flow/data/branch.rb', line 7 def updated_at @updated_at end |
Class Method Details
.from_hash(hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flash_flow/data/branch.rb', line 20 def self.from_hash(hash) branch = new(hash['remote'], hash['remote_url'], hash['ref']) branch.sha = hash['sha'] branch.status = hash['status'] branch.merge_order = hash['merge_order'] branch.resolutions = hash['resolutions'] branch.stories = hash['stories'] branch. = hash['metadata'] branch.conflict_sha = hash['conflict_sha'] || hash['metadata'].to_h['conflict_sha'] branch.updated_at = massage_time(hash['updated_at']) branch.created_at = massage_time(hash['created_at']) branch end |
.massage_time(time) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/flash_flow/data/branch.rb', line 34 def self.massage_time(time) case time when Time time when NilClass Time.now else Time.parse(time) end end |
Instance Method Details
#==(other) ⇒ Object
45 46 47 |
# File 'lib/flash_flow/data/branch.rb', line 45 def ==(other) other.remote_url == remote_url && other.remote == remote && other.ref == ref end |
#add_metadata(data) ⇒ Object
85 86 87 88 |
# File 'lib/flash_flow/data/branch.rb', line 85 def (data) self. ||= {} self..merge!(data) end |
#deleted! ⇒ Object
119 120 121 |
# File 'lib/flash_flow/data/branch.rb', line 119 def deleted! self.status = 'deleted' end |
#deleted? ⇒ Boolean
123 124 125 |
# File 'lib/flash_flow/data/branch.rb', line 123 def deleted? self.status == 'deleted' end |
#fail!(conflict_sha = nil) ⇒ Object
102 103 104 105 |
# File 'lib/flash_flow/data/branch.rb', line 102 def fail!(conflict_sha=nil) self.conflict_sha = conflict_sha self.status = 'fail' end |
#fail? ⇒ Boolean
107 108 109 |
# File 'lib/flash_flow/data/branch.rb', line 107 def fail? self.status == 'fail' end |
#merge(other) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/flash_flow/data/branch.rb', line 71 def merge(other) unless other.nil? self.sha = other.sha self.status = other.status self.merge_order = other.merge_order self.resolutions = other.resolutions self.stories = self.stories.to_a | other.stories.to_a self.updated_at = Time.now self.created_at = [(self.created_at || Time.now), (other.created_at || Time.now)].min end self end |
#removed! ⇒ Object
111 112 113 |
# File 'lib/flash_flow/data/branch.rb', line 111 def removed! self.status = 'removed' end |
#removed? ⇒ Boolean
115 116 117 |
# File 'lib/flash_flow/data/branch.rb', line 115 def removed? self.status == 'removed' end |
#set_resolutions(_resolutions) ⇒ Object
90 91 92 |
# File 'lib/flash_flow/data/branch.rb', line 90 def set_resolutions(_resolutions) self.resolutions = _resolutions end |
#success! ⇒ Object
94 95 96 |
# File 'lib/flash_flow/data/branch.rb', line 94 def success! self.status = 'success' end |
#success? ⇒ Boolean
98 99 100 |
# File 'lib/flash_flow/data/branch.rb', line 98 def success? self.status == 'success' end |
#to_hash ⇒ Object Also known as: to_h
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/flash_flow/data/branch.rb', line 49 def to_hash { 'remote' => remote, 'remote_url' => remote_url, 'ref' => ref, 'sha' => sha, 'status' => status, 'merge_order' => merge_order, 'resolutions' => resolutions, 'stories' => stories, 'conflict_sha' => conflict_sha, 'metadata' => , 'updated_at' => updated_at, 'created_at' => created_at, } end |
#to_json(_) ⇒ Object
67 68 69 |
# File 'lib/flash_flow/data/branch.rb', line 67 def to_json(_) JSON.pretty_generate(to_hash) end |
#unknown! ⇒ Object
127 128 129 |
# File 'lib/flash_flow/data/branch.rb', line 127 def unknown! self.status = nil end |
#unknown? ⇒ Boolean
131 132 133 |
# File 'lib/flash_flow/data/branch.rb', line 131 def unknown? self.status.nil? end |