Module: Nearline
- Defined in:
- lib/nearline/log.rb,
lib/nearline/block.rb,
lib/nearline/schema.rb,
lib/nearline/manifest.rb,
lib/nearline/file_content.rb,
lib/nearline/archived_file.rb,
lib/nearline/module_methods.rb
Defined Under Namespace
Modules: Models
Constant Summary collapse
- AR_MODELS =
Every model using an ActiveRecord connection
[ Nearline::Models::ArchivedFile, Nearline::Models::Block, Nearline::Models::FileContent, Nearline::Models::Manifest, Nearline::Models::Sequence, Nearline::Models::Log ]
Class Method Summary collapse
-
.backup(system_name, backup_paths, backup_exclusions = []) ⇒ Object
Performs a backup labeled for system_name, Recursing through a single string or an array of backup_paths, Excluding any path matching any of the regular expressions in the backup_exclusions array or single string.
-
.connect(config = "development") ⇒ Object
Establishes a connection only to the Nearline ActiveDirectory models.
-
.connect!(config = "development") ⇒ Object
Establishes the ActiveRecord connection.
-
.restore(system_name) ⇒ Object
Restore all missing files from the latest backup for system_name.
- .string_to_array(x) ⇒ Object
Class Method Details
.backup(system_name, backup_paths, backup_exclusions = []) ⇒ Object
Performs a backup labeled for system_name, Recursing through a single string or an array of backup_paths, Excluding any path matching any of the regular expressions in the backup_exclusions array or single string.
Expects the Nearline database connection has already been established
Returns a Manifest for the backup
85 86 87 88 89 90 91 |
# File 'lib/nearline/module_methods.rb', line 85 def backup(system_name, backup_paths,backup_exclusions= []) Nearline::Models::Manifest.backup( system_name, string_to_array(backup_paths), string_to_array(backup_exclusions) ) end |
.connect(config = "development") ⇒ Object
Establishes a connection only to the Nearline ActiveDirectory models
Will not change the ActiveRecord::Base connection
Will not establish Nearline tables in the database
Accepts a Hash to establish the connection or a String referring to an entry in config/database.yml.
Examples
Nearline.connect(=> ‘sqlite3’, :database => ‘data/sqlite.db’)
Nearline.connect ‘production’
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nearline/module_methods.rb', line 60 def connect(config="development") # These are the ActiveRecord models in place # Each one needs an explicit establish_connection # if you don't want it running though ActiveRecord::Base if (config.is_a? String) hash = YAML.load_file("config/database.yml")[config] else hash = config end AR_MODELS.each do |m| m.establish_connection(hash) end Nearline::Models::Block.connected? end |
.connect!(config = "development") ⇒ Object
Establishes the ActiveRecord connection
Accepts a Hash to establish the connection or a String referring to an entry in config/database.yml.
Will establish the Nearline database tables if they are absent.
Stomps on any ActiveRecord::Base.establish_connection you might have already established.
Examples
Nearline.connect!(=> ‘sqlite3’, :database => ‘data/sqlite.db’)
Nearline.connect! ‘production’
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nearline/module_methods.rb', line 30 def connect!(config="development") if (config.is_a? String) ActiveRecord::Base.establish_connection( YAML.load_file("config/database.yml")[config] ) end if (config.is_a? Hash) ActiveRecord::Base.establish_connection(config) end unless Nearline::Models::Block.table_exists? Nearline::Models.generate_schema end Nearline::Models::Block.connected? end |
.restore(system_name) ⇒ Object
Restore all missing files from the latest backup for system_name
All updated or existing files are left alone
Expects the Nearline database connection has already been established
Returns an Array of paths restored
109 110 111 |
# File 'lib/nearline/module_methods.rb', line 109 def restore(system_name) Nearline::Models::Manifest.restore_all_missing(system_name) end |
.string_to_array(x) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/nearline/module_methods.rb', line 93 def string_to_array(x) if x.is_a? String return [x] end x end |