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
- #base_with_parent ⇒ Object
- #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) path = base.split('/') @parent = path.pop if parent @base = path.join('/') 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
#base_with_parent ⇒ Object
34 35 36 |
# File 'lib/workers_loader/path.rb', line 34 def base_with_parent parent.nil? ? base : File.join(base, parent) end |
#class_for(relative_path) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/workers_loader/path.rb', line 21 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 |
# File 'lib/workers_loader/path.rb', line 15 def files path = File.join(base_with_parent, '{**/*.rb}') Dir[path] .map { |file| /#{base}\/(.*).rb/.match(file)[1] } end |
#queue_for(relative_path) ⇒ Object
30 31 32 |
# File 'lib/workers_loader/path.rb', line 30 def queue_for(relative_path) Resque.queue_from_class(class_for(relative_path)) end |