Class: XMigra::Plugin
Overview
Base class for XMigra plugins.
Derive a class from this class, then call XMigra::Plugin.activate! with a block that instantiates your class.
require "xmigra/plugin"
class YearTemplatePlugin < XMigra::Plugin
def amend_composed_sql(sql)
sql.gsub! '[{year}]', Date.today.year.to_s
end
end
XMigra::Plugin.activate! {YearTemplatePlugin.new}
The last call to XMigra::Plugin.activate! will determine which block will be executed to return the active plugin, so make sure to require any plugins to be aggregated before activating your own.
Defined Under Namespace
Classes: LoadingError
Class Attribute Summary collapse
-
.active ⇒ Object
readonly
Returns the value of attribute active.
Class Method Summary collapse
Instance Method Summary collapse
-
#amend_access_artifact(artifact) ⇒ Object
Amend each included access artifact.
-
#amend_composed_sql(sql) ⇒ Object
Amend SQL for script after all parts are combined.
-
#amend_index(index) ⇒ Object
Amend each included index.
-
#amend_source_sql(sql) ⇒ Object
Amend SQL coming from source documents.
-
#each_additional_access_artifact(db_specifics = nil) ⇒ Object
Yields additional access artifacts to include in the logical schema.
-
#each_additional_index(db_specifics = nil) ⇒ Object
Yields additional indexes to include in the logical schema.
-
#include_access_artifact?(artifact) ⇒ Boolean
Indicate if the access artifact (stored procedure, user defined function, or view) should be included in the logical schema.
-
#include_index?(index) ⇒ Boolean
Indicate if the index should be included in the logical schema.
Class Attribute Details
.active ⇒ Object (readonly)
Returns the value of attribute active.
26 27 28 |
# File 'lib/xmigra/plugin.rb', line 26 def active @active end |
Class Method Details
.activate!(&blk) ⇒ Object
52 53 54 |
# File 'lib/xmigra/plugin.rb', line 52 def activate!(&blk) @activation = blk end |
.load!(name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xmigra/plugin.rb', line 32 def load!(name) previous_depth, @load_depth = @load_depth, (@load_depth || 0) + 1 @activation = nil if previous_depth.nil? begin require name rescue ::LoadError => error if previous_depth.nil? && error.path == name raise LoadingError, "The XMigra plugin #{name.inspect} is not installed (Kernel#require failed)." else raise end ensure @load_depth = previous_depth end if previous_depth.nil? && @activation @active = @activation.call end end |
.loading? ⇒ Boolean
28 29 30 |
# File 'lib/xmigra/plugin.rb', line 28 def loading? !!@load_depth end |
Instance Method Details
#amend_access_artifact(artifact) ⇒ Object
Amend each included access artifact.
artifact - an XMigra::StoredProcedure, XMigra::Function, or XMigra::View
The default implementation does nothing.
101 102 |
# File 'lib/xmigra/plugin.rb', line 101 def amend_access_artifact(artifact) end |
#amend_composed_sql(sql) ⇒ Object
Amend SQL for script after all parts are combined. This method will have an opportunity to amend all of the SQL in the output script, including SQL generated by XMigra.
XMigra only calls this method one time for the entire output script prior to any transformation necessary for script transactionality (e.g. splitting the script into batches and encoding as string literals). The one exception to this is for any branch upgrade SQL, which will already be encoded in one or more string literals.
The default implementation does nothing.
81 82 |
# File 'lib/xmigra/plugin.rb', line 81 def amend_composed_sql(sql) end |
#amend_index(index) ⇒ Object
Amend each included index.
The default implementation does nothing.
132 133 |
# File 'lib/xmigra/plugin.rb', line 132 def amend_index(index) end |
#amend_source_sql(sql) ⇒ Object
Amend SQL coming from source documents. The String object passed to this method will be included in the commands to run, and any modifications made to this object will be reflected in the script. XMigra only calls this method to amend SQL read in from source files.
The default implementation does nothing.
65 66 |
# File 'lib/xmigra/plugin.rb', line 65 def amend_source_sql(sql) end |
#each_additional_access_artifact(db_specifics = nil) ⇒ Object
Yields additional access artifacts to include in the logical schema.
db_specifics - A module providing methods useful for building SQL
specific to the target RDBMS.
The yielded artifact objects must respond to name, depends_on and definition_sql.
The default implementation does not yield any objects.
115 116 |
# File 'lib/xmigra/plugin.rb', line 115 def each_additional_access_artifact(db_specifics=nil) # :yields: artifact end |
#each_additional_index(db_specifics = nil) ⇒ Object
Yields additional indexes to include in the logical schema.
db_specifics - A module providing methods useful for building SQL
specific to the target RDBMS.
The yielded index objects must respond to name and definition_sql.
The default implementation does not yield any objects.
145 146 |
# File 'lib/xmigra/plugin.rb', line 145 def each_additional_index(db_specifics=nil) # :yields: index end |
#include_access_artifact?(artifact) ⇒ Boolean
Indicate if the access artifact (stored procedure, user defined function, or view) should be included in the logical schema.
The default implementation always returns true.
90 91 92 |
# File 'lib/xmigra/plugin.rb', line 90 def include_access_artifact?(artifact) true end |
#include_index?(index) ⇒ Boolean
Indicate if the index should be included in the logical schema.
The default implementation always return true.
123 124 125 |
# File 'lib/xmigra/plugin.rb', line 123 def include_index?(index) true end |