Class: KtCommon::GitDataStore
- Inherits:
-
Object
- Object
- KtCommon::GitDataStore
- Defined in:
- lib/ktcommon/gitdatastore.rb
Overview
GitDataStore encapsulates a Git repository
Instance Method Summary collapse
- #create(path, data) ⇒ Object
- #delete(path) ⇒ Object
-
#initialize(location) ⇒ GitDataStore
constructor
A new instance of GitDataStore.
- #location(location) ⇒ Object
-
#read(path) ⇒ Object
Read a specific file from the store based on a path.
-
#read_path(path) ⇒ Object
Read data from the store based on a path.
- #store ⇒ Object
- #update(path, data) ⇒ Object
- #ymlPath(path) ⇒ Object
Constructor Details
#initialize(location) ⇒ GitDataStore
Returns a new instance of GitDataStore.
21 22 23 24 25 |
# File 'lib/ktcommon/gitdatastore.rb', line 21 def initialize(location) $LOG.debug "GitDataStore::new" @location = location @store = nil end |
Instance Method Details
#create(path, data) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/ktcommon/gitdatastore.rb', line 58 def create(path, data) $LOG.debug "GitDataStore::create" store[ymlPath(path)] = data commitMsg = "Added to data store: #{ymlPath(path)}" store.commit commitMsg end |
#delete(path) ⇒ Object
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ktcommon/gitdatastore.rb', line 98 def delete(path) $LOG.debug "GitDataStore::delete" result = store.delete ymlPath(path) commitMsg = "Deleted from data store: #{ymlPath(path)}" store.commit commitMsg return result end |
#location(location) ⇒ Object
52 53 54 55 |
# File 'lib/ktcommon/gitdatastore.rb', line 52 def location(location) raise ArgumentError.new("Repo already opened when new location submitted: #{location}") unless @store.nil? @location = location end |
#read(path) ⇒ Object
Read a specific file from the store based on a path.
- path
-
path to retrieve data from
- returns
-
one(1) data object
71 72 73 74 75 |
# File 'lib/ktcommon/gitdatastore.rb', line 71 def read(path) $LOG.debug "GitDataStore::read(#{ymlPath(path)})" return store[ymlPath(path)] end |
#read_path(path) ⇒ Object
Read data from the store based on a path.
- path
-
path to retrieve data from
- returns
-
a Hash of data
82 83 84 85 86 |
# File 'lib/ktcommon/gitdatastore.rb', line 82 def read_path(path) $LOG.debug "GitDataStore::read_path(#{path})" return store[path] end |
#store ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ktcommon/gitdatastore.rb', line 38 def store() return @store unless @store.nil? raise ArgumentError.new("No repo location provided before store requested.") unless (!@location.nil? && !@location.empty?) begin @store = GitStore.new(@location) rescue ArgumentError => e if(e..include?("must be a valid Git repo")) raise RuntimeError.new("Cannot find a valid Git repo. Are you sure you've initialized the dir at #{@location}?") end raise $: end end |
#update(path, data) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/ktcommon/gitdatastore.rb', line 89 def update(path, data) $LOG.debug "GitDataStore::update" store[ymlPath(path)] = data commitMsg = "Updated data store: #{ymlPath(path)}" store.commit commitMsg end |
#ymlPath(path) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/ktcommon/gitdatastore.rb', line 28 def ymlPath(path) #puts "IN: #{path}" raise ArgumentError.new("Empty path") if (path.nil? || path.empty?) path += ".yml" unless !File.extname(path).empty? #puts "OUT: #{path}" return path end |