Class: Blueprints::BlueprintNameProxy
- Inherits:
-
Object
- Object
- Blueprints::BlueprintNameProxy
- Defined in:
- lib/blueprints/blueprint_name_proxy.rb
Overview
Acts as a proxy to buildables with regexp names. Used for caching purposes. Remembers name used and always uses it later. Allows building and demolishing it’s buildable.
Instance Method Summary collapse
-
#build(environment, options = {}) ⇒ Object
Allows building buildable.
-
#demolish(environment) ⇒ Object
Allows demolishing buildable.
-
#initialize(name, buildable) ⇒ BlueprintNameProxy
constructor
Initializes new instance of proxy.
Constructor Details
#initialize(name, buildable) ⇒ BlueprintNameProxy
Initializes new instance of proxy.
7 8 9 10 11 12 13 14 15 |
# File 'lib/blueprints/blueprint_name_proxy.rb', line 7 def initialize(name, buildable) @buildable = buildable @name = name match_data = buildable.name.match(name.to_s) names = match_data.names.collect(&:to_sym) if match_data.respond_to?(:names) names = (0...match_data.captures.size).collect { |ind| :"arg#{ind}" } if names.blank? @options = Hash[names.zip(match_data.captures)] end |
Instance Method Details
#build(environment, options = {}) ⇒ Object
Allows building buildable. Merges regexp match data into options. If named regexp captures are used (Ruby 1.9 only), it will merge those names with appropriate values into options, otherwise options will be named arg0..n.
22 23 24 25 26 27 |
# File 'lib/blueprints/blueprint_name_proxy.rb', line 22 def build(environment, = {}) [:options] ||= {} [:options].merge!(@options) .merge!(:name => @name) @buildable.build(environment, ) end |
#demolish(environment) ⇒ Object
Allows demolishing buildable. Uses remembered name to determine name of variable to call destroy on.
31 32 33 |
# File 'lib/blueprints/blueprint_name_proxy.rb', line 31 def demolish(environment) @buildable.demolish(environment, @name) end |