Class: FlashFlow::Data::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/flash_flow/data/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branch_config, filename, git, opts = {}) ⇒ Base

Returns a new instance of Base.



19
20
21
22
23
# File 'lib/flash_flow/data/base.rb', line 19

def initialize(branch_config, filename, git, opts={})
  @git = git
  @store = Store.new(filename, git, opts)
  @collection = initialize_collection(branch_config)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



17
18
19
# File 'lib/flash_flow/data/base.rb', line 17

def collection
  @collection
end

Instance Method Details

#initialize_collection(branch_config) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/flash_flow/data/base.rb', line 25

def initialize_collection(branch_config)
  stored_collection = Collection.from_hash(stored_branches)

  if ! branch_config.empty?
    collection = Collection.fetch(branch_config)
    # Order matters. We are marking the PRs as current, not the branches stored in the json
    collection.mark_all_as_current
    collection = collection.reverse_merge(stored_collection)

  else
    collection = stored_collection
    collection.mark_all_as_current
  end

  collection.branches.delete_if { |k, v|  TimeHelper.massage_time(v.updated_at) < Time.now - TimeHelper.two_weeks  }

  collection
end

#merged_branchesObject



68
69
70
# File 'lib/flash_flow/data/base.rb', line 68

def merged_branches
  @collection.reverse_merge(Collection.from_hash({}, stored_branches))
end

#pending_releaseObject



80
81
82
# File 'lib/flash_flow/data/base.rb', line 80

def pending_release
  releases.detect { |r| r['status'] == 'Pending' }
end

#ready_to_merge_releaseObject



84
85
86
# File 'lib/flash_flow/data/base.rb', line 84

def ready_to_merge_release
  releases.detect { |r| r['status'] == 'Ready to merge' }
end

#releasesObject



64
65
66
# File 'lib/flash_flow/data/base.rb', line 64

def releases
  @releases ||= stored_data['releases'] || []
end

#save!Object



48
49
50
# File 'lib/flash_flow/data/base.rb', line 48

def save!
  @store.write(to_hash)
end

#saved_branchesObject



76
77
78
# File 'lib/flash_flow/data/base.rb', line 76

def saved_branches
  Collection.from_hash(stored_branches).to_a
end

#stored_branchesObject



60
61
62
# File 'lib/flash_flow/data/base.rb', line 60

def stored_branches
  @stored_branches ||= stored_data['branches'] || {}
end

#stored_dataObject



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

def stored_data
  @stored_data ||= @store.get
end

#to_hashObject



52
53
54
55
56
57
58
# File 'lib/flash_flow/data/base.rb', line 52

def to_hash
  {
      'version'  => FlashFlow::VERSION,
      'branches' => @collection.to_hash,
      'releases' => releases
  }
end

#versionObject



44
45
46
# File 'lib/flash_flow/data/base.rb', line 44

def version
  stored_data['version']
end