Class: AdminModule::Snapshots
- Inherits:
-
Object
- Object
- AdminModule::Snapshots
- Defined in:
- lib/admin_module/snapshots.rb
Instance Attribute Summary collapse
-
#page_factory ⇒ Object
readonly
Returns the value of attribute page_factory.
Instance Method Summary collapse
- #export(file_path) ⇒ Object
- #import(file_path) ⇒ Object
-
#initialize(page_factory) ⇒ Snapshots
constructor
A new instance of Snapshots.
- #list ⇒ Object
- #read(name) ⇒ Object
- #rename(src, dest) ⇒ Object
Constructor Details
#initialize(page_factory) ⇒ Snapshots
Returns a new instance of Snapshots.
15 16 17 |
# File 'lib/admin_module/snapshots.rb', line 15 def initialize page_factory @page_factory = page_factory end |
Instance Attribute Details
#page_factory ⇒ Object (readonly)
Returns the value of attribute page_factory.
13 14 15 |
# File 'lib/admin_module/snapshots.rb', line 13 def page_factory @page_factory end |
Instance Method Details
#export(file_path) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/admin_module/snapshots.rb', line 53 def export file_path defns = list export_data = {} defns.each do |defn| export_data[defn] = read defn end File.open(file_path, 'w') do |f| f.write export_data.to_yaml end rescue Exception => e if e..include? 'No such file or directory' raise IOError, "No such directory - #{file_path}" else raise e end end |
#import(file_path) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/admin_module/snapshots.rb', line 33 def import file_path assert_file_exists file_path defns = {} File.open(file_path, 'r') do |f| # Read array of definition hashes defns = YAML.load(f) end existing_defns = list defns.each do |name, data| if existing_defns.include?(name) update(data) else create(data) end end end |
#list ⇒ Object
19 20 21 |
# File 'lib/admin_module/snapshots.rb', line 19 def list snapshot_page.get_definitions end |
#read(name) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/admin_module/snapshots.rb', line 73 def read name name = assert_definition_exists name snapshot_page .modify(name) .get_definition_data end |
#rename(src, dest) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/admin_module/snapshots.rb', line 23 def rename src, dest src = assert_definition_exists src dest = assert_definition_does_not_exist dest snapshot_page .modify(src) .set_name(dest) .save end |