Class: ConfigTemplates::Collections::Components
- Inherits:
-
Object
- Object
- ConfigTemplates::Collections::Components
- Defined in:
- lib/config_templates/collections/components.rb
Instance Method Summary collapse
- #<<(component) ⇒ Object
- #find_all ⇒ Object
- #find_by!(criteria) ⇒ Object
- #find_by_path!(path, relative_to = nil) ⇒ Object
-
#initialize(criteria) ⇒ Components
constructor
A new instance of Components.
Constructor Details
#initialize(criteria) ⇒ Components
Returns a new instance of Components.
3 4 5 6 |
# File 'lib/config_templates/collections/components.rb', line 3 def initialize(criteria) @criteria = criteria @components = {} end |
Instance Method Details
#<<(component) ⇒ Object
8 9 10 |
# File 'lib/config_templates/collections/components.rb', line 8 def <<(component) @components[component.source_path] = component end |
#find_all ⇒ Object
12 13 14 15 16 |
# File 'lib/config_templates/collections/components.rb', line 12 def find_all @criteria.filter(@components).lazy .reject { |_, component| component.child? } .map { |_, component| component } end |
#find_by!(criteria) ⇒ Object
24 25 26 27 28 |
# File 'lib/config_templates/collections/components.rb', line 24 def find_by!(criteria) criteria.filter(@components).first.last rescue raise ConfigTemplates::Errors::ComponentNotFound end |
#find_by_path!(path, relative_to = nil) ⇒ Object
18 19 20 21 22 |
# File 'lib/config_templates/collections/components.rb', line 18 def find_by_path!(path, relative_to = nil) find_by! ConfigTemplates::Criteria::Path.new path, relative_to rescue raise ConfigTemplates::Errors::ComponentNotFound, path end |