class SQLtorial::AssembleCommand
Public Instance Methods
dir()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 42 def dir @dir ||= path.directory? ? path : path.dirname end
execute()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 10 def execute global_options[:watch] ? watch : process end
files()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 50 def files path.directory? ? Pathname.glob('*.sql') : files_from_file end
files_from_file()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 54 def files_from_file path.readlines.map(&:chomp!).select { |l| l !~ /^\s*#/ && !l.empty? }.map do |file_name| Pathname.new(file_name) end end
path()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 46 def path @path ||= Pathname.new(arguments.first || ".") end
process()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 23 def process FileUtils.rm_rf(".sqltorial_cache") if global_options[:ignore_cache] process_dir.chdir do preface = Pathname.new(global_options[:preface]) if global_options[:preface] File.open(global_options[:output], 'w') do |f| f.puts preface.read if preface && preface.exist? examples = files.map.with_index do |file, index| Escort::Logger.output.puts "Examplizing #{file.to_s}" SqlToExample.new(file, db, index + 1).to_str(global_options) end f.puts(examples.join("\n\n")) end end end
process_dir()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 38 def process_dir @process_dir = path.directory? ? path : Pathname.pwd end
watch()
click to toggle source
# File lib/sqltorial/assemble_command.rb, line 14 def watch listener = Listen.to(dir) do |modified, added, removed| process end listener.only(/\.sql$/) listener.start sleep while listener.processing? end