Class: New::Source
- Inherits:
-
Object
- Object
- New::Source
- Defined in:
- lib/new/source.rb
Constant Summary collapse
- @@sources =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
INSTANCE METHODS.
-
#path ⇒ Object
readonly
INSTANCE METHODS.
-
#tasks ⇒ Object
readonly
INSTANCE METHODS.
Class Method Summary collapse
-
.find_task(task_name, source_name = nil) ⇒ String
look through all sources to find a matching task.
-
.load_sources ⇒ Object
loop through sources saved to the global new object and initializes sources from them.
- .sources ⇒ Object
Instance Attribute Details
#name ⇒ Object (readonly)
INSTANCE METHODS
78 79 80 |
# File 'lib/new/source.rb', line 78 def name @name end |
#path ⇒ Object (readonly)
INSTANCE METHODS
78 79 80 |
# File 'lib/new/source.rb', line 78 def path @path end |
#tasks ⇒ Object (readonly)
INSTANCE METHODS
78 79 80 |
# File 'lib/new/source.rb', line 78 def tasks @tasks end |
Class Method Details
.find_task(task_name, source_name = nil) ⇒ String
look through all sources to find a matching task
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/new/source.rb', line 27 def find_task task_name, source_name = nil # if source is specified, target it directly if source_name return lookup_task source_name, task_name # if source and task is specified in a single string elsif task_name.to_s.include? '#' source_task = task_name.split('#').reverse source_name = source_task[1].to_sym task_name = source_task[0].to_sym return lookup_task source_name, task_name # otherwise loop through sources until a template is found else @@sources.values.each do |source| return source.tasks[task_name.to_sym] || next end S.ay "No `#{task_name}` task was found in any of the sources", :error end return nil end |
.load_sources ⇒ Object
loop through sources saved to the global new object and initializes sources from them
15 16 17 18 19 |
# File 'lib/new/source.rb', line 15 def load_sources New.new_object[:sources].each do |name, path| @@sources[name] = New::Source.new name, path end end |
.sources ⇒ Object
11 |
# File 'lib/new/source.rb', line 11 def sources; @@sources; end |