Class: CassSchema::Runner
- Inherits:
-
Object
- Object
- CassSchema::Runner
- Defined in:
- lib/cass_schema/runner.rb
Defined Under Namespace
Classes: DropCommandsNotAllowed
Instance Attribute Summary collapse
-
#cluster_builder ⇒ Object
readonly
Returns the value of attribute cluster_builder.
-
#datastores ⇒ Object
readonly
Returns the value of attribute datastores.
-
#disallow_drops ⇒ Object
readonly
Returns the value of attribute disallow_drops.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#schema_base_path ⇒ Object
readonly
Returns the value of attribute schema_base_path.
Class Method Summary collapse
-
.setup(options = {}) ⇒ Object
Create a new Runner drop commands will raise an exception instead of executing the command.
Instance Method Summary collapse
-
#create(datastore_name) ⇒ Object
Create the schema for a particular datastore.
-
#create_all ⇒ Object
Create all schemas for all datastores.
-
#datastore_lookup(datastore_name) ⇒ CassSchema::Datastore
Find a datastore based on the datastore name.
-
#drop(datastore_name) ⇒ Object
Drop the schema for a particular datastore.
-
#drop_all ⇒ Object
Drop all schemas for all datastores.
-
#initialize(options = {}) ⇒ Runner
constructor
Create a new Runner drop commands will raise an exception instead of executing the command.
-
#migrate(datastore_name, migration_name) ⇒ Object
Run a particular named migration for a datastore.
Constructor Details
#initialize(options = {}) ⇒ Runner
Create a new Runner drop commands will raise an exception instead of executing the command.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cass_schema/runner.rb', line 20 def initialize( = {}) [:schema_base_path] ||= defined?(::Rails) ? File.join(::Rails.root, 'cass_schema') : nil @datastores = [:datastores] @schema_base_path = [:schema_base_path] @logger = [:logger] @disallow_drops = [:disallow_drops] raise ":datastores is a required argument!" unless @datastores @datastores.each { |ds| ds._setup() } end |
Instance Attribute Details
#cluster_builder ⇒ Object (readonly)
Returns the value of attribute cluster_builder.
10 11 12 |
# File 'lib/cass_schema/runner.rb', line 10 def cluster_builder @cluster_builder end |
#datastores ⇒ Object (readonly)
Returns the value of attribute datastores.
10 11 12 |
# File 'lib/cass_schema/runner.rb', line 10 def datastores @datastores end |
#disallow_drops ⇒ Object (readonly)
Returns the value of attribute disallow_drops.
10 11 12 |
# File 'lib/cass_schema/runner.rb', line 10 def disallow_drops @disallow_drops end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/cass_schema/runner.rb', line 10 def logger @logger end |
#schema_base_path ⇒ Object (readonly)
Returns the value of attribute schema_base_path.
10 11 12 |
# File 'lib/cass_schema/runner.rb', line 10 def schema_base_path @schema_base_path end |
Class Method Details
.setup(options = {}) ⇒ Object
Create a new Runner drop commands will raise an exception instead of executing the command.
76 77 78 |
# File 'lib/cass_schema/runner.rb', line 76 def setup( = {}) @runner = Runner.new() end |
Instance Method Details
#create(datastore_name) ⇒ Object
Create the schema for a particular datastore
46 47 48 |
# File 'lib/cass_schema/runner.rb', line 46 def create(datastore_name) datastore_lookup(datastore_name).create end |
#create_all ⇒ Object
Create all schemas for all datastores
34 35 36 |
# File 'lib/cass_schema/runner.rb', line 34 def create_all datastores.each { |d| d.create } end |
#datastore_lookup(datastore_name) ⇒ CassSchema::Datastore
Find a datastore based on the datastore name
67 68 69 70 |
# File 'lib/cass_schema/runner.rb', line 67 def datastore_lookup(datastore_name) @datastore_lookup ||= Hash[datastores.map { |ds| [ds.name, ds] }] @datastore_lookup[datastore_name.to_s] || (raise ArgumentError.new("CassSchema datastore #{datastore_name} not found")) end |
#drop(datastore_name) ⇒ Object
Drop the schema for a particular datastore
52 53 54 55 |
# File 'lib/cass_schema/runner.rb', line 52 def drop(datastore_name) raise DropCommandsNotAllowed if disallow_drops datastore_lookup(datastore_name).drop end |
#drop_all ⇒ Object
Drop all schemas for all datastores
39 40 41 42 |
# File 'lib/cass_schema/runner.rb', line 39 def drop_all raise DropCommandsNotAllowed if disallow_drops datastores.each { |d| d.drop } end |
#migrate(datastore_name, migration_name) ⇒ Object
Run a particular named migration for a datastore
60 61 62 |
# File 'lib/cass_schema/runner.rb', line 60 def migrate(datastore_name, migration_name) datastore_lookup(datastore_name).migrate(migration_name) end |