lib/cfer/block.rb in cfer-0.3.0 vs lib/cfer/block.rb in cfer-0.4.0
- old
+ new
@@ -28,6 +28,48 @@
# Executed just after the DSL is evaluated
def post_block
end
end
+
+ class BlockHash < Block
+ NON_PROXIED_METHODS = [:parameters, :options, :lookup_output]
+
+ def properties(keyvals = {})
+ self.merge!(keyvals)
+ end
+
+ def get_property(key)
+ self.fetch key
+ end
+
+ def respond_to?(method_sym)
+ !non_proxied_methods.include?(method_sym)
+ end
+
+ def method_missing(method_sym, *arguments, &block)
+ key = camelize_property(method_sym)
+ properties key =>
+ case arguments.size
+ when 0
+ if block
+ BlockHash.new.build_from_block(&block)
+ else
+ raise "Expected a value or block when setting property #{key}"
+ end
+ when 1
+ arguments.first
+ else
+ arguments
+ end
+ end
+
+ private
+ def non_proxied_methods
+ NON_PROXIED_METHODS
+ end
+
+ def camelize_property(sym)
+ sym.to_s.camelize.to_sym
+ end
+ end
end