Class: SimplyGenius::Atmos::SourcePath

Inherits:
Object
  • Object
show all
Includes:
GemLogger::LoggerSupport
Defined in:
lib/simplygenius/atmos/source_path.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, location) ⇒ SourcePath

Returns a new instance of SourcePath.



46
47
48
49
# File 'lib/simplygenius/atmos/source_path.rb', line 46

def initialize(name, location)
  @name = name
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



18
19
20
# File 'lib/simplygenius/atmos/source_path.rb', line 18

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/simplygenius/atmos/source_path.rb', line 18

def name
  @name
end

Class Method Details

.clear_registryObject



20
21
22
23
# File 'lib/simplygenius/atmos/source_path.rb', line 20

def self.clear_registry
  registry.clear
  @resolved_templates.clear if @resolved_templates
end

.find_template(template_name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/simplygenius/atmos/source_path.rb', line 31

def self.find_template(template_name)
  @resolved_templates ||= {}
  @resolved_templates[template_name] ||= begin
    tmpls = registry.collect {|name, sp| sp.template(template_name) }.compact

    if tmpls.size == 0
      raise ArgumentError.new("Could not find the template: #{template_name}")
    elsif tmpls.size > 1
      raise ArgumentError.new("Template names must be unique, #{template_name} exists in multiple sources: #{tmpls.collect(&:source)}")
    end

    tmpls.first
  end
end

.register(name, location) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
# File 'lib/simplygenius/atmos/source_path.rb', line 25

def self.register(name, location)
  sp = SourcePath.new(name, location)
  raise ArgumentError.new("Source paths must be uniquely named: #{sp}") if registry[name]
  registry[name] = sp
end

Instance Method Details

#directoryObject



59
60
61
62
63
64
65
66
# File 'lib/simplygenius/atmos/source_path.rb', line 59

def directory
  if @directory_resolved
    @directory
  else
    @directory_resolved = true
    @directory = expand_location
  end
end

#template(name) ⇒ Object



72
73
74
# File 'lib/simplygenius/atmos/source_path.rb', line 72

def template(name)
  templates[name]
end

#template_namesObject



68
69
70
# File 'lib/simplygenius/atmos/source_path.rb', line 68

def template_names
  templates.keys.sort
end

#to_hObject



55
56
57
# File 'lib/simplygenius/atmos/source_path.rb', line 55

def to_h
  SettingsHash.new({name: name, location: location})
end

#to_sObject



51
52
53
# File 'lib/simplygenius/atmos/source_path.rb', line 51

def to_s
  "#{name} (#{location})"
end