Class: New::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/new/source.rb

Constant Summary collapse

@@sources =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

INSTANCE METHODS



78
79
80
# File 'lib/new/source.rb', line 78

def name
  @name
end

#pathObject (readonly)

INSTANCE METHODS



78
79
80
# File 'lib/new/source.rb', line 78

def path
  @path
end

#tasksObject (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

Parameters:

  • task_name (String/Symbol)

    valid task name

  • source_name (String/Symbol) (defaults to: nil)

    valid source name

Returns:

  • (String)

    valid task path



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_sourcesObject

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

.sourcesObject



11
# File 'lib/new/source.rb', line 11

def sources; @@sources; end