Class: SchemaDev::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/schema_dev/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby:, rails:, db: nil) ⇒ Executor

Returns a new instance of Executor.



10
11
12
13
# File 'lib/schema_dev/executor.rb', line 10

def initialize(ruby:, rails:, db: nil)
  @ruby_selector = RubySelector.command(ruby)
  @gemfile_selector = GemfileSelector.command(rails: rails, db: db)
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



8
9
10
# File 'lib/schema_dev/executor.rb', line 8

def db
  @db
end

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/schema_dev/executor.rb', line 8

def error
  @error
end

#railsObject (readonly)

Returns the value of attribute rails.



8
9
10
# File 'lib/schema_dev/executor.rb', line 8

def rails
  @rails
end

#rubyObject (readonly)

Returns the value of attribute ruby.



8
9
10
# File 'lib/schema_dev/executor.rb', line 8

def ruby
  @ruby
end

Instance Method Details

#run(cmd, dry_run: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/schema_dev/executor.rb', line 15

def run(cmd, dry_run: false)
  fullcommand = ["/usr/bin/env", @gemfile_selector, @ruby_selector, cmd].compact.join(' ')
  puts "* #{fullcommand}"
  return true if dry_run

  Tempfile.open('SchemaDev') do |file|
    @error = !system(%Q[ (#{fullcommand}) 2>& 1 | tee #{file.path} ])
    file.rewind
    @error ||= file.readlines.grep(/(^Failed examples)|(rake aborted)|(LoadError)/).any?
  end

  return !@error
end