class Scheman::Commands::Diff
Constants
- DEFAULT_AFTER_SCHEMA_PATH
- DEFAULT_TYPE
Public Class Methods
new(argv)
click to toggle source
@param argv [Array] ARGV
# File lib/scheman/commands/diff.rb, line 9 def initialize(argv) @argv = argv end
Public Instance Methods
call()
click to toggle source
Outputs a schema diff
# File lib/scheman/commands/diff.rb, line 14 def call print diff end
Private Instance Methods
after()
click to toggle source
# File lib/scheman/commands/diff.rb, line 31 def after case when after_schema_path File.read(after_schema_path) when has_default_schema_file? default_schema else "CREATE DATABASE database_name;" end end
after_schema_path()
click to toggle source
@return [String, nil] Path to a next schema
# File lib/scheman/commands/diff.rb, line 79 def after_schema_path options[:after] end
before()
click to toggle source
# File lib/scheman/commands/diff.rb, line 20 def before case when has_input_from_stdin? STDIN.read when before_schema_path File.read(before_schema_path) else raise Errors::NoBeforeSchema end end
before_schema_path()
click to toggle source
@return [String, nil] Path to a previous schema
# File lib/scheman/commands/diff.rb, line 74 def before_schema_path options[:before] end
default_schema()
click to toggle source
@return [String, nil]
# File lib/scheman/commands/diff.rb, line 89 def default_schema File.read(DEFAULT_AFTER_SCHEMA_PATH) end
diff()
click to toggle source
@return [Schema::Diff]
# File lib/scheman/commands/diff.rb, line 50 def diff @diff ||= Scheman::Diff.new( before: before, after: after, type: type, ) end
has_default_schema_file?()
click to toggle source
@return [String, nil] True if a schema file exists in the default schema file path
# File lib/scheman/commands/diff.rb, line 84 def has_default_schema_file? File.exist?(DEFAULT_AFTER_SCHEMA_PATH) end
has_input_from_stdin?()
click to toggle source
@return [true, false] True if any input given via STDIN
# File lib/scheman/commands/diff.rb, line 59 def has_input_from_stdin? has_pipe_input? || has_redirect_input? end
has_pipe_input?()
click to toggle source
@return [true, false] True if any input given from redirection
# File lib/scheman/commands/diff.rb, line 64 def has_pipe_input? File.pipe?(STDIN) end
has_redirect_input?()
click to toggle source
@return [true, false] True if any input given from redirection
# File lib/scheman/commands/diff.rb, line 69 def has_redirect_input? File.select([STDIN], [], [], 0) != nil end
options()
click to toggle source
# File lib/scheman/commands/diff.rb, line 93 def options @options ||= Slop.parse!(@argv, help: true) do banner "Usage: #{$0} diff [options]" on "type=", "SQL type (e.g. mysql)" on "before=", "Path to the previous schema file" on "after=", "Path to the next schema file" end end
type()
click to toggle source
@return [String] @example
"mysql"
# File lib/scheman/commands/diff.rb, line 45 def type options[:type] || DEFAULT_TYPE end