Class: SQLtorial::AssembleCommand
- Inherits:
-
Escort::ActionCommand::Base
- Object
- Escort::ActionCommand::Base
- SQLtorial::AssembleCommand
- Includes:
- Sequelizer
- Defined in:
- lib/sqltorial/assemble_command.rb
Instance Method Summary collapse
- #execute ⇒ Object
- #files ⇒ Object
- #files_from_file ⇒ Object
- #path ⇒ Object
- #process ⇒ Object
- #process_dir ⇒ Object
- #watch ⇒ Object
Instance Method Details
#execute ⇒ Object
9 10 11 |
# File 'lib/sqltorial/assemble_command.rb', line 9 def execute [:watch] ? watch : process end |
#files ⇒ Object
44 45 46 |
# File 'lib/sqltorial/assemble_command.rb', line 44 def files path.directory? ? Pathname.glob('*.sql') : files_from_file end |
#files_from_file ⇒ Object
48 49 50 51 52 |
# File 'lib/sqltorial/assemble_command.rb', line 48 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 ⇒ Object
40 41 42 |
# File 'lib/sqltorial/assemble_command.rb', line 40 def path @path ||= Pathname.new(arguments.first || ".") end |
#process ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sqltorial/assemble_command.rb', line 22 def process process_dir.chdir do preface = Pathname.new([:preface]) if [:preface] File.open([: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(![:no_results]) end f.puts(examples.join("\n\n")) end end end |
#process_dir ⇒ Object
36 37 38 |
# File 'lib/sqltorial/assemble_command.rb', line 36 def process_dir @process_dir = path.directory? ? path : Pathname.pwd end |
#watch ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/sqltorial/assemble_command.rb', line 13 def watch listener = Listen.to(path) do |modified, added, removed| process end listener.only(/\.sql$/) listener.start sleep while listener.processing? end |