Class: Quaker::Templates
- Inherits:
-
Object
- Object
- Quaker::Templates
- Defined in:
- lib/quaker/templates.rb
Instance Method Summary collapse
- #apply(services) ⇒ Object
- #extend_with_matchine_templates(service, templates) ⇒ Object
- #template?(k) ⇒ Boolean
Instance Method Details
#apply(services) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/quaker/templates.rb', line 5 def apply services templates = services.select {|name, v| template?(name)} services .reject {|name, v| template?(name)} .inject({}) {|acc, (name, spec)| acc.update(name => extend_with_matchine_templates(spec, templates)) } end |
#extend_with_matchine_templates(service, templates) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/quaker/templates.rb', line 14 def extend_with_matchine_templates service, templates templates .select {|name, spec| Quaker::TagMatcher::match(service["tags"], spec["tags"])} .inject(service) {|svc, (_, spec)| filtered_template_content = spec .select{|name, spec| name != 'tags' } svc.merge(filtered_template_content) } end |
#template?(k) ⇒ Boolean
24 25 26 |
# File 'lib/quaker/templates.rb', line 24 def template?(k) !!(k =~ /_template$/) end |