Class: WorkersLoader::Path
- Inherits:
-
Object
- Object
- WorkersLoader::Path
- Defined in:
- lib/workers_loader/path.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
- #class_for(relative_path) ⇒ Object
- #files ⇒ Object
-
#initialize(base, parent = true) ⇒ Path
constructor
A new instance of Path.
- #queue_for(relative_path) ⇒ Object
Constructor Details
#initialize(base, parent = true) ⇒ Path
Returns a new instance of Path.
8 9 10 11 12 13 |
# File 'lib/workers_loader/path.rb', line 8 def initialize(base, parent = true) base = match[1] if match = /(.*)\/$/.match(base) @base = base @parent = base.split('/').last if parent end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
6 7 8 |
# File 'lib/workers_loader/path.rb', line 6 def base @base end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/workers_loader/path.rb', line 6 def parent @parent end |
Instance Method Details
#class_for(relative_path) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/workers_loader/path.rb', line 22 def class_for(relative_path) relative_path.split('/').map(&:camelize).join('::').constantize rescue NameError file = File.join(base, "#{relative_path}.rb") raise "File not found: #{file}" unless File.exist?(file) load file class_for(relative_path) end |
#files ⇒ Object
15 16 17 18 19 20 |
# File 'lib/workers_loader/path.rb', line 15 def files path = File.join(base, '{**/*.rb}') Dir[path] .map { |file| /#{base}\/(.*).rb/.match(file)[1] } .map { |relative_path| relative_path_for(relative_path) } end |
#queue_for(relative_path) ⇒ Object
31 32 33 |
# File 'lib/workers_loader/path.rb', line 31 def queue_for(relative_path) Resque.queue_from_class(class_for(relative_path)) end |