Class: FlashFlow::Data::Store
- Inherits:
-
Object
- Object
- FlashFlow::Data::Store
- Defined in:
- lib/flash_flow/data/store.rb
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(filename, git, opts = {}) ⇒ Store
constructor
A new instance of Store.
- #write(branches, file = nil) ⇒ Object
Constructor Details
#initialize(filename, git, opts = {}) ⇒ Store
Returns a new instance of Store.
7 8 9 10 11 |
# File 'lib/flash_flow/data/store.rb', line 7 def initialize(filename, git, opts={}) @filename = filename @git = git @logger = opts[:logger] || Logger.new('/dev/null') end |
Instance Method Details
#get ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/flash_flow/data/store.rb', line 13 def get file_contents = @git.read_file_from_merge_branch(@filename) JSON.parse(file_contents) rescue JSON::ParserError, Errno::ENOENT @logger.error "Unable to read branch info from file: #{@filename}" {} end |
#write(branches, file = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flash_flow/data/store.rb', line 22 def write(branches, file=nil) @git.in_dir do file ||= File.open(@filename, 'w') file.puts JSON.pretty_generate(sort_branches(branches)) file.close end @git.in_temp_merge_branch do @git.add_and_commit(@filename, 'Branch Info', add: {force: true}) end end |