Class: ShopifyToolkit::Migration
- Inherits:
-
Object
- Object
- ShopifyToolkit::Migration
- Includes:
- AdminClient, MetafieldStatements, MetaobjectStatements, Logging
- Defined in:
- lib/shopify_toolkit/migration.rb
Defined Under Namespace
Modules: Logging Classes: IrreversibleMigration
Constant Summary
Constants included from AdminClient
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #announce(message) ⇒ Object
- #down ⇒ Object
-
#initialize(name, version) ⇒ Migration
constructor
A new instance of Migration.
- #logger ⇒ Object
- #migrate(direction) ⇒ Object
- #up ⇒ Object
Methods included from Logging
Methods included from MetaobjectStatements
define, #get_metaobject_definition_gid, log_time, #update_metaobject_definition
Methods included from AdminClient
#api_version, #handle_shopify_admin_client_errors, #shopify_admin_client
Methods included from MetafieldStatements
define, #get_metafield_gid, log_time
Constructor Details
#initialize(name, version) ⇒ Migration
Returns a new instance of Migration.
30 31 32 33 |
# File 'lib/shopify_toolkit/migration.rb', line 30 def initialize(name, version) @name = name @version = version end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
28 29 30 |
# File 'lib/shopify_toolkit/migration.rb', line 28 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
28 29 30 |
# File 'lib/shopify_toolkit/migration.rb', line 28 def version @version end |
Class Method Details
.[](api_version) ⇒ Object
22 23 24 25 26 |
# File 'lib/shopify_toolkit/migration.rb', line 22 def self.[](api_version) klass = Class.new(self) klass.const_set(:API_VERSION, api_version) klass end |
Instance Method Details
#announce(message) ⇒ Object
35 36 37 |
# File 'lib/shopify_toolkit/migration.rb', line 35 def announce() super "#{version} #{name}: #{}" end |
#down ⇒ Object
60 61 62 |
# File 'lib/shopify_toolkit/migration.rb', line 60 def down raise IrreversibleMigration end |
#logger ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/shopify_toolkit/migration.rb', line 14 def logger @logger ||= ActiveSupport::Logger.new(STDOUT).tap do |logger| logger.formatter = proc do |severity, datetime, progname, msg| "#{severity}: #{msg}\n" end end end |
#migrate(direction) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/shopify_toolkit/migration.rb', line 39 def migrate(direction) case direction when :up announce("migrating") time_elapsed = ActiveSupport::Benchmark.realtime { up } announce("migrated (%.4fs)" % time_elapsed) when :down announce("reverting") time_elapsed = ActiveSupport::Benchmark.realtime { down } announce("reverted (%.4fs)" % time_elapsed) else raise ArgumentError, "Unknown migration direction: #{direction}" end end |
#up ⇒ Object
56 57 58 |
# File 'lib/shopify_toolkit/migration.rb', line 56 def up # Implement in subclass end |