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



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

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
# File 'lib/flash_flow/data/base.rb', line 21

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

#merged_branchesObject



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

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

#save!Object



30
31
32
# File 'lib/flash_flow/data/base.rb', line 30

def save!
  @store.write(to_hash)
end

#saved_branchesObject



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

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

#to_hashObject



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

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

#versionObject



26
27
28
# File 'lib/flash_flow/data/base.rb', line 26

def version
  backwards_compatible_store['version']
end