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
Instance Method Details
#execute ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sqltorial/assemble_command.rb', line 8 def execute 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 |
#files ⇒ Object
30 31 32 |
# File 'lib/sqltorial/assemble_command.rb', line 30 def files path.directory? ? Pathname.glob('*.sql') : files_from_file end |
#files_from_file ⇒ Object
34 35 36 37 38 |
# File 'lib/sqltorial/assemble_command.rb', line 34 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
26 27 28 |
# File 'lib/sqltorial/assemble_command.rb', line 26 def path @path ||= Pathname.new(arguments.first || ".") end |
#process_dir ⇒ Object
22 23 24 |
# File 'lib/sqltorial/assemble_command.rb', line 22 def process_dir @process_dir = path.directory? ? path : Pathname.pwd end |