Class: FlashFlow::Data::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/flash_flow/data/branch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_shaObject

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_atObject

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_recordObject

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_orderObject

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

#metadataObject

Returns the value of attribute metadata.



7
8
9
# File 'lib/flash_flow/data/branch.rb', line 7

def 
  @metadata
end

#refObject

Returns the value of attribute ref.



7
8
9
# File 'lib/flash_flow/data/branch.rb', line 7

def ref
  @ref
end

#remoteObject

Returns the value of attribute remote.



7
8
9
# File 'lib/flash_flow/data/branch.rb', line 7

def remote
  @remote
end

#remote_urlObject

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

#resolutionsObject

Returns the value of attribute resolutions.



7
8
9
# File 'lib/flash_flow/data/branch.rb', line 7

def resolutions
  @resolutions
end

#shaObject

Returns the value of attribute sha.



7
8
9
# File 'lib/flash_flow/data/branch.rb', line 7

def sha
  @sha
end

#statusObject

Returns the value of attribute status.



7
8
9
# File 'lib/flash_flow/data/branch.rb', line 7

def status
  @status
end

#storiesObject

Returns the value of attribute stories.



7
8
9
# File 'lib/flash_flow/data/branch.rb', line 7

def stories
  @stories
end

#updated_atObject

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


99
100
101
# File 'lib/flash_flow/data/branch.rb', line 99

def success?
  self.status == 'success'
end

#to_hashObject 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

Returns:

  • (Boolean)


132
133
134
# File 'lib/flash_flow/data/branch.rb', line 132

def unknown?
  self.status.nil?
end