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 19 |
# 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 = [] @metadata = {} @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
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flash_flow/data/branch.rb', line 21 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
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/flash_flow/data/branch.rb', line 35 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
46 47 48 |
# File 'lib/flash_flow/data/branch.rb', line 46 def ==(other) other.remote_url == remote_url && other.remote == remote && other.ref == ref end |
#add_metadata(data) ⇒ Object
86 87 88 89 |
# File 'lib/flash_flow/data/branch.rb', line 86 def (data) self. ||= {} self..merge!(data) end |
#deleted! ⇒ Object
120 121 122 |
# File 'lib/flash_flow/data/branch.rb', line 120 def deleted! self.status = 'deleted' end |
#deleted? ⇒ Boolean
124 125 126 |
# File 'lib/flash_flow/data/branch.rb', line 124 def deleted? self.status == 'deleted' end |
#fail!(conflict_sha = nil) ⇒ Object
103 104 105 106 |
# File 'lib/flash_flow/data/branch.rb', line 103 def fail!(conflict_sha=nil) self.conflict_sha = conflict_sha self.status = 'fail' end |
#fail? ⇒ Boolean
108 109 110 |
# File 'lib/flash_flow/data/branch.rb', line 108 def fail? self.status == 'fail' end |
#merge(other) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/flash_flow/data/branch.rb', line 72 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
112 113 114 |
# File 'lib/flash_flow/data/branch.rb', line 112 def removed! self.status = 'removed' end |
#removed? ⇒ Boolean
116 117 118 |
# File 'lib/flash_flow/data/branch.rb', line 116 def removed? self.status == 'removed' end |
#set_resolutions(_resolutions) ⇒ Object
91 92 93 |
# File 'lib/flash_flow/data/branch.rb', line 91 def set_resolutions(_resolutions) self.resolutions = _resolutions end |
#success! ⇒ Object
95 96 97 |
# File 'lib/flash_flow/data/branch.rb', line 95 def success! self.status = 'success' end |
#success? ⇒ Boolean
99 100 101 |
# File 'lib/flash_flow/data/branch.rb', line 99 def success? self.status == 'success' end |
#to_hash ⇒ Object Also known as: to_h
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/flash_flow/data/branch.rb', line 50 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
68 69 70 |
# File 'lib/flash_flow/data/branch.rb', line 68 def to_json(_) JSON.pretty_generate(to_hash) end |
#unknown! ⇒ Object
128 129 130 |
# File 'lib/flash_flow/data/branch.rb', line 128 def unknown! self.status = nil end |
#unknown? ⇒ Boolean
132 133 134 |
# File 'lib/flash_flow/data/branch.rb', line 132 def unknown? self.status.nil? end |