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(_ref) ⇒ Branch

Returns a new instance of Branch.



11
12
13
14
15
16
17
18
# File 'lib/flash_flow/data/branch.rb', line 11

def initialize(_ref)
  @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.



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

def conflict_sha
  @conflict_sha
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#current_recordObject

Returns the value of attribute current_record.



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

def current_record
  @current_record
end

#merge_orderObject

Returns the value of attribute merge_order.



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

def merge_order
  @merge_order
end

#metadataObject

Returns the value of attribute metadata.



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

def 
  @metadata
end

#refObject

Returns the value of attribute ref.



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

def ref
  @ref
end

#resolutionsObject

Returns the value of attribute resolutions.



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

def resolutions
  @resolutions
end

#shaObject

Returns the value of attribute sha.



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

def sha
  @sha
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#storiesObject

Returns the value of attribute stories.



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

def stories
  @stories
end

#updated_atObject

Returns the value of attribute updated_at.



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

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['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 = TimeHelper.massage_time(hash['updated_at'])
  branch.created_at = TimeHelper.massage_time(hash['created_at'])
  branch
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
# File 'lib/flash_flow/data/branch.rb', line 34

def ==(other)
  other.ref == ref
end

#add_metadata(data) ⇒ Object



72
73
74
75
# File 'lib/flash_flow/data/branch.rb', line 72

def (data)
  self. ||= {}
  self..merge!(data)
end

#deleted!Object



106
107
108
# File 'lib/flash_flow/data/branch.rb', line 106

def deleted!
  self.status = 'deleted'
end

#deleted?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/flash_flow/data/branch.rb', line 110

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

#fail!(conflict_sha = nil) ⇒ Object



89
90
91
92
# File 'lib/flash_flow/data/branch.rb', line 89

def fail!(conflict_sha=nil)
  self.conflict_sha = conflict_sha
  self.status = 'fail'
end

#fail?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/flash_flow/data/branch.rb', line 94

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

#merge(other) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/flash_flow/data/branch.rb', line 58

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



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

def removed!
  self.status = 'removed'
end

#removed?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/flash_flow/data/branch.rb', line 102

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

#set_resolutions(_resolutions) ⇒ Object



77
78
79
# File 'lib/flash_flow/data/branch.rb', line 77

def set_resolutions(_resolutions)
  self.resolutions = _resolutions
end

#success!Object



81
82
83
# File 'lib/flash_flow/data/branch.rb', line 81

def success!
  self.status = 'success'
end

#success?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/flash_flow/data/branch.rb', line 85

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

#to_hashObject Also known as: to_h



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/flash_flow/data/branch.rb', line 38

def to_hash
  {
      '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



54
55
56
# File 'lib/flash_flow/data/branch.rb', line 54

def to_json(_)
  JSON.pretty_generate(to_hash)
end

#unknown!Object



114
115
116
# File 'lib/flash_flow/data/branch.rb', line 114

def unknown!
  self.status = nil
end

#unknown?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/flash_flow/data/branch.rb', line 118

def unknown?
  self.status.nil?
end