Class: ContentfulMigrations::Migration
- Inherits:
-
Object
- Object
- ContentfulMigrations::Migration
- Defined in:
- lib/contentful_migrations/migration.rb
Instance Attribute Summary collapse
-
#contentful_client ⇒ Object
readonly
Returns the value of attribute contentful_client.
-
#contentful_space ⇒ Object
readonly
Returns the value of attribute contentful_space.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #erase_migration(migration_content_type) ⇒ Object
-
#initialize(name = self.class.name, version = nil, client = nil, space = nil) ⇒ Migration
constructor
A new instance of Migration.
- #migrate(direction, client, space) ⇒ Object
- #record_migration(migration_content_type) ⇒ Object
- #with_editor_interfaces {|contentful_client.editor_interfaces| ... } ⇒ Object
- #with_space {|contentful_space| ... } ⇒ Object
Constructor Details
#initialize(name = self.class.name, version = nil, client = nil, space = nil) ⇒ Migration
Returns a new instance of Migration.
5 6 7 8 9 10 |
# File 'lib/contentful_migrations/migration.rb', line 5 def initialize(name = self.class.name, version = nil, client = nil, space = nil) @name = name @version = version @contentful_client = client @contentful_space = space end |
Instance Attribute Details
#contentful_client ⇒ Object (readonly)
Returns the value of attribute contentful_client.
3 4 5 |
# File 'lib/contentful_migrations/migration.rb', line 3 def contentful_client @contentful_client end |
#contentful_space ⇒ Object (readonly)
Returns the value of attribute contentful_space.
3 4 5 |
# File 'lib/contentful_migrations/migration.rb', line 3 def contentful_space @contentful_space end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/contentful_migrations/migration.rb', line 3 def name @name end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
3 4 5 |
# File 'lib/contentful_migrations/migration.rb', line 3 def version @version end |
Instance Method Details
#erase_migration(migration_content_type) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/contentful_migrations/migration.rb', line 34 def erase_migration(migration_content_type) entry = migration_content_type.entries.all.find { |m| m.version.to_i == version.to_i } return unless entry entry.unpublish entry.destroy entry end |
#migrate(direction, client, space) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/contentful_migrations/migration.rb', line 12 def migrate(direction, client, space) @contentful_client = client @contentful_space = space send(direction) self end |
#record_migration(migration_content_type) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/contentful_migrations/migration.rb', line 27 def record_migration(migration_content_type) entry = migration_content_type.entries.create(version: version) entry.save entry.publish entry end |
#with_editor_interfaces {|contentful_client.editor_interfaces| ... } ⇒ Object
23 24 25 |
# File 'lib/contentful_migrations/migration.rb', line 23 def with_editor_interfaces yield(contentful_client.editor_interfaces) end |
#with_space {|contentful_space| ... } ⇒ Object
19 20 21 |
# File 'lib/contentful_migrations/migration.rb', line 19 def with_space yield(contentful_space) end |