Class: SimplyGenius::Atmos::SourcePath
- Inherits:
-
Object
- Object
- SimplyGenius::Atmos::SourcePath
- Includes:
- GemLogger::LoggerSupport
- Defined in:
- lib/simplygenius/atmos/source_path.rb
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #directory ⇒ Object
-
#initialize(name, location) ⇒ SourcePath
constructor
A new instance of SourcePath.
- #template(name) ⇒ Object
- #template_names ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
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
#location ⇒ Object (readonly)
Returns the value of attribute location.
18 19 20 |
# File 'lib/simplygenius/atmos/source_path.rb', line 18 def location @location end |
#name ⇒ Object (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_registry ⇒ Object
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
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
#directory ⇒ Object
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 = end end |
#template(name) ⇒ Object
72 73 74 |
# File 'lib/simplygenius/atmos/source_path.rb', line 72 def template(name) templates[name] end |
#template_names ⇒ Object
68 69 70 |
# File 'lib/simplygenius/atmos/source_path.rb', line 68 def template_names templates.keys.sort end |
#to_h ⇒ Object
55 56 57 |
# File 'lib/simplygenius/atmos/source_path.rb', line 55 def to_h SettingsHash.new({name: name, location: location}) end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/simplygenius/atmos/source_path.rb', line 51 def to_s "#{name} (#{location})" end |