Class: FlashFlow::Data::Base

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



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

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 Method Details

#backwards_compatible_storeObject



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

def backwards_compatible_store
  @backwards_compatible_store ||= begin
    hash = in_shadow_repo do
      @store.get
    end

    hash.has_key?('branches') ? hash : { 'branches' => hash }
  end
end

#initialize_collection(branch_config, remotes) ⇒ Object



21
22
23
24
25
26
# File 'lib/flash_flow/data/base.rb', line 21

def initialize_collection(branch_config, remotes)
  collection = Collection.fetch(remotes, branch_config) ||
      Collection.from_hash(remotes, backwards_compatible_store['branches'])
  collection.mark_all_as_current
  collection
end

#merged_branchesObject



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

def merged_branches
  @collection.reverse_merge(Collection.from_hash({}, backwards_compatible_store['branches']))
end

#save!Object



32
33
34
# File 'lib/flash_flow/data/base.rb', line 32

def save!
  @store.write(to_hash)
end

#saved_branchesObject



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

def saved_branches
  Collection.from_hash(@git.remotes, backwards_compatible_store['branches']).to_a
end

#to_hashObject



36
37
38
39
40
41
# File 'lib/flash_flow/data/base.rb', line 36

def to_hash
  {
      'version'  => FlashFlow::VERSION,
      'branches' => merged_branches.to_hash
  }
end

#versionObject



28
29
30
# File 'lib/flash_flow/data/base.rb', line 28

def version
  backwards_compatible_store['version']
end