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
- #dir ⇒ Object
- #execute ⇒ Object
- #files ⇒ Object
- #files_from_file ⇒ Object
- #path ⇒ Object
- #process ⇒ Object
- #process_dir ⇒ Object
- #watch ⇒ Object
Instance Method Details
#dir ⇒ Object
42 43 44 |
# File 'lib/sqltorial/assemble_command.rb', line 42 def dir @dir ||= path.directory? ? path : path.dirname end |
#execute ⇒ Object
10 11 12 |
# File 'lib/sqltorial/assemble_command.rb', line 10 def execute [:watch] ? watch : process end |
#files ⇒ Object
50 51 52 |
# File 'lib/sqltorial/assemble_command.rb', line 50 def files path.directory? ? Pathname.glob('*.sql') : files_from_file end |
#files_from_file ⇒ Object
54 55 56 57 58 |
# 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 ⇒ Object
46 47 48 |
# File 'lib/sqltorial/assemble_command.rb', line 46 def path @path ||= Pathname.new(arguments.first || ".") end |
#process ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sqltorial/assemble_command.rb', line 23 def process FileUtils.rm_rf(".sqltorial_cache") if [:ignore_cache] 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() end f.puts(examples.join("\n\n")) end end end |
#process_dir ⇒ Object
38 39 40 |
# File 'lib/sqltorial/assemble_command.rb', line 38 def process_dir @process_dir = path.directory? ? path : Pathname.pwd end |
#watch ⇒ Object
14 15 16 17 18 19 20 21 |
# 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 |