Class: Plotline::Import::Runner
- Inherits:
-
Object
- Object
- Plotline::Import::Runner
- Defined in:
- lib/plotline/import/runner.rb
Constant Summary collapse
- HANDLERS =
[ Plotline::Import::Handlers::MarkdownFile, Plotline::Import::Handlers::ImageFile, Plotline::Import::Handlers::VideoFile ].freeze
- IGNORED_FILES =
So far this includes only the annoying Iconr file on OSX, which is hidden, but it’s not a dotfile, so Dir lookup doesn’t ignore it…
This file appears when a directory has a custom icon (e.g shared dropbox folder).
[ "Icon\r" ].freeze
Instance Attribute Summary collapse
-
#public_dir ⇒ Object
readonly
Returns the value of attribute public_dir.
-
#source_dir ⇒ Object
readonly
Returns the value of attribute source_dir.
-
#target_dir ⇒ Object
readonly
Returns the value of attribute target_dir.
-
#uploads_dir ⇒ Object
readonly
Returns the value of attribute uploads_dir.
Instance Method Summary collapse
- #import_all! ⇒ Object
-
#initialize(source_dir, target_dir) ⇒ Runner
constructor
A new instance of Runner.
- #process_files(files) ⇒ Object
Constructor Details
#initialize(source_dir, target_dir) ⇒ Runner
Returns a new instance of Runner.
23 24 25 26 27 28 29 30 |
# File 'lib/plotline/import/runner.rb', line 23 def initialize(source_dir, target_dir) @source_dir = source_dir @target_dir = target_dir @public_dir = target_dir + '/public' @uploads_dir = target_dir + '/public/uploads' @handlers = HANDLERS.map { |klass| klass.new(self) } end |
Instance Attribute Details
#public_dir ⇒ Object (readonly)
Returns the value of attribute public_dir.
21 22 23 |
# File 'lib/plotline/import/runner.rb', line 21 def public_dir @public_dir end |
#source_dir ⇒ Object (readonly)
Returns the value of attribute source_dir.
21 22 23 |
# File 'lib/plotline/import/runner.rb', line 21 def source_dir @source_dir end |
#target_dir ⇒ Object (readonly)
Returns the value of attribute target_dir.
21 22 23 |
# File 'lib/plotline/import/runner.rb', line 21 def target_dir @target_dir end |
#uploads_dir ⇒ Object (readonly)
Returns the value of attribute uploads_dir.
21 22 23 |
# File 'lib/plotline/import/runner.rb', line 21 def uploads_dir @uploads_dir end |
Instance Method Details
#import_all! ⇒ Object
32 33 34 |
# File 'lib/plotline/import/runner.rb', line 32 def import_all! process_files(Dir[@source_dir + '/**/*']) end |
#process_files(files) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/plotline/import/runner.rb', line 36 def process_files(files) files.each do |filename| next if FileTest.directory?(filename) next if IGNORED_FILES.include?(File.basename(filename)) handler_found = false @handlers.each do |handler| if handler.supported_file?(filename) handler.import(filename) handler_found = true end end raise UnsupportedFileType.new(filename) unless handler_found end end |