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



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

Returns:

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

Returns:

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

Returns:

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

Returns:

  • (Boolean)


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

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

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

Returns:

  • (Boolean)


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

def unknown?
  self.status.nil?
end