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.



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

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

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



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

def collection
  @collection
end

Instance Method Details

#initialize_collection(branch_config, remotes) ⇒ Object



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

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

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

  else
    collection = stored_collection
    collection.mark_all_as_current
    collection
  end
end

#merged_branchesObject



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

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

#releasesObject



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

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

#save!Object



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

def save!
  @store.write(to_hash)
end

#saved_branchesObject



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

def saved_branches
  Collection.from_hash(@git.remotes, stored_branches).to_a
end

#stored_branchesObject



56
57
58
# File 'lib/flash_flow/data/base.rb', line 56

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

#stored_dataObject



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

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

#to_hashObject



48
49
50
51
52
53
54
# File 'lib/flash_flow/data/base.rb', line 48

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

#versionObject



40
41
42
# File 'lib/flash_flow/data/base.rb', line 40

def version
  stored_data['version']
end