Class: Cassie::Schema::VersionWriter
- Defined in:
- lib/cassie/schema/version_writer.rb
Instance Attribute Summary collapse
-
#down_code ⇒ Object
Returns the value of attribute down_code.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#up_code ⇒ Object
Returns the value of attribute up_code.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #basename ⇒ Object
- #directory ⇒ Object
- #existing_file ⇒ Object
- #filename ⇒ Object
-
#initialize(version, io = nil) ⇒ VersionWriter
constructor
A new instance of VersionWriter.
- #migration_contents ⇒ Object
- #migration_contents=(contents) ⇒ Object
- #with_io ⇒ Object
-
#write ⇒ String
Writes the version’s migration clas code to a new ruby migraton file in the
Cassie::Schema.paths[:migrations_directory]
.
Constructor Details
#initialize(version, io = nil) ⇒ VersionWriter
Returns a new instance of VersionWriter.
11 12 13 14 15 16 17 18 |
# File 'lib/cassie/schema/version_writer.rb', line 11 def initialize(version, io=nil) @io = io @version = version @up_code = default_up_code @down_code = default_down_code ensure_dir_exist end |
Instance Attribute Details
#down_code ⇒ Object
Returns the value of attribute down_code.
9 10 11 |
# File 'lib/cassie/schema/version_writer.rb', line 9 def down_code @down_code end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
5 6 7 |
# File 'lib/cassie/schema/version_writer.rb', line 5 def io @io end |
#up_code ⇒ Object
Returns the value of attribute up_code.
8 9 10 |
# File 'lib/cassie/schema/version_writer.rb', line 8 def up_code @up_code end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/cassie/schema/version_writer.rb', line 6 def version @version end |
Instance Method Details
#basename ⇒ Object
62 63 64 |
# File 'lib/cassie/schema/version_writer.rb', line 62 def basename "#{version_prefix}#{description_suffix}.rb" end |
#directory ⇒ Object
58 59 60 |
# File 'lib/cassie/schema/version_writer.rb', line 58 def directory Cassie::Schema.paths[:migrations_directory] end |
#existing_file ⇒ Object
66 67 68 |
# File 'lib/cassie/schema/version_writer.rb', line 66 def existing_file Dir.glob("#{directory}/#{version_prefix}*.rb").first end |
#filename ⇒ Object
54 55 56 |
# File 'lib/cassie/schema/version_writer.rb', line 54 def filename "#{directory}/#{basename}" end |
#migration_contents ⇒ Object
49 50 51 52 |
# File 'lib/cassie/schema/version_writer.rb', line 49 def migration_contents return @migration_contents if defined?(@migration_contents) build_migration_contents end |
#migration_contents=(contents) ⇒ Object
45 46 47 |
# File 'lib/cassie/schema/version_writer.rb', line 45 def migration_contents=(contents) @migration_contents = contents end |
#with_io ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cassie/schema/version_writer.rb', line 31 def with_io if io.respond_to?(:<<) yield io else ensure_unique_version File.open(filename, 'w'){ |file| yield file } # load the file, so the definition for source # for the methods will come from that file # instead of (eval) load File.absolute_path(filename) filename end end |
#write ⇒ String
Writes the version’s migration clas code to a new ruby migraton file in the Cassie::Schema.paths[:migrations_directory]
25 26 27 28 29 |
# File 'lib/cassie/schema/version_writer.rb', line 25 def write with_io do |io| io << migration_contents end end |