Module: Runbook::Util::Repo
- Defined in:
- lib/runbook/util/repo.rb
Constant Summary collapse
- FILE_ID =
"data"
Class Method Summary collapse
- ._file(book_title) ⇒ Object
- ._slug(title) ⇒ Object
- .delete(title) ⇒ Object
- .load(metadata) ⇒ Object
- .register_delete_stored_repo_hook(base) ⇒ Object
- .register_save_repo_hook(base) ⇒ Object
- .save(repo, book_title:) ⇒ Object
Class Method Details
._file(book_title) ⇒ Object
25 26 27 |
# File 'lib/runbook/util/repo.rb', line 25 def self._file(book_title) "#{Dir.tmpdir}/runbook_#{FILE_ID}_#{ENV["USER"]}_#{_slug(book_title)}.yml" end |
._slug(title) ⇒ Object
29 30 31 |
# File 'lib/runbook/util/repo.rb', line 29 def self._slug(title) title.titleize.gsub(/\s+/, "").underscore.dasherize end |
.delete(title) ⇒ Object
21 22 23 |
# File 'lib/runbook/util/repo.rb', line 21 def self.delete(title) FileUtils.rm_f(_file(title)) end |
.load(metadata) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/runbook/util/repo.rb', line 5 def self.load() title = [:book_title] file = _file(title) if File.exists?(file) msg = "Repo file #{file} detected. Loading previous state..." [:toolbox].output(msg) [:repo] = ::YAML::load_file(file) end end |
.register_delete_stored_repo_hook(base) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/runbook/util/repo.rb', line 45 def self.register_delete_stored_repo_hook(base) base.register_hook( :delete_stored_repo_hook, :after, Runbook::Entities::Book, ) do |object, | title = [:book_title] Runbook::Util::Repo.delete(title) end end |
.register_save_repo_hook(base) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/runbook/util/repo.rb', line 33 def self.register_save_repo_hook(base) base.register_hook( :save_repo_hook, :after, Object, ) do |object, | repo = [:repo] title = [:book_title] Runbook::Util::Repo.save(repo, book_title: title) end end |
.save(repo, book_title:) ⇒ Object
15 16 17 18 19 |
# File 'lib/runbook/util/repo.rb', line 15 def self.save(repo, book_title:) File.open(_file(book_title), 'w') do |f| f.write(repo.to_yaml) end end |