class FeatureDefinitions
Constants
- IDENTITY
Attributes
test_proc[R]
Public Class Methods
context=(context)
click to toggle source
# File lib/feature_definitions.rb, line 25 def self.context=(context) Thread.current[:FeatureDefinitionsTLS] = context end
define_feature(name, &feature_test_block)
click to toggle source
# File lib/feature_definitions.rb, line 4 def self.define_feature(name, &feature_test_block) feature = new(&feature_test_block) meta_class = class << self; self end meta_class.__send__(:define_method, name) do |&feature_impl_block| if block_given? feature.enabled?(&feature_impl_block) end feature end end
new(&block)
click to toggle source
# File lib/feature_definitions.rb, line 17 def initialize(&block) if block_given? @test_proc = block.to_proc else @test_proc = IDENTITY end end
Public Instance Methods
context()
click to toggle source
# File lib/feature_definitions.rb, line 29 def context Thread.current[:FeatureDefinitionsTLS] end
enabled?() { || ... }
click to toggle source
# File lib/feature_definitions.rb, line 33 def enabled?(&block) eval_test_proc.tap do |verdict| if verdict and block_given? yield end end end
eval_test_proc()
click to toggle source
# File lib/feature_definitions.rb, line 41 def eval_test_proc if test_proc.arity == 0 context.instance_exec(&test_proc) else test_proc.call(context) end end