class ComposeEnv::Context
Attributes
current_env[R]
options[R]
Public Class Methods
new(options, current_env)
click to toggle source
# File lib/compose_env/context.rb, line 6 def initialize(options, current_env) @options = options @current_env = current_env end
Public Instance Methods
env()
click to toggle source
# File lib/compose_env/context.rb, line 19 def env self end
env?(*env_names, &block)
click to toggle source
# File lib/compose_env/context.rb, line 23 def env?(*env_names, &block) return unless block_given? first_env = env_names.first env_names = first_env.is_a?(Array) ? first_env : env_names return unless env_names.map(&:to_sym).include?(current_env) block.call(self) end
env_methods()
click to toggle source
# File lib/compose_env/context.rb, line 63 def env_methods return @env_methods unless @env_methods.nil? options.envs.each_with_object({test: [], restriction: []}) do |env, acc| test_method = "#{env}?".to_sym acc[:test] << test_method acc[:restriction] << env end end
get_binding()
click to toggle source
# File lib/compose_env/context.rb, line 33 def get_binding binding end
handle_restriction_method(method_name, &block)
click to toggle source
# File lib/compose_env/context.rb, line 41 def handle_restriction_method(method_name, &block) return unless block_given? && method_name == current_env block.call(self) end
handle_test_method(method_name)
click to toggle source
# File lib/compose_env/context.rb, line 37 def handle_test_method(method_name) return method_name == "#{current_env}?".to_sym end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/compose_env/context.rb, line 11 def method_missing(name, *args, &block) method_name = name.to_sym return handle_test_method(method_name) if test_method?(method_name) return handle_restriction_method(method_name, &block) if restriction_method?(method_name) super end
restriction_method?(method_name)
click to toggle source
# File lib/compose_env/context.rb, line 51 def restriction_method?(method_name) restriction_methods.include?(method_name) end
restriction_methods()
click to toggle source
# File lib/compose_env/context.rb, line 59 def restriction_methods @restriction_methods ||= env_methods[:restriction] end
test_method?(method_name)
click to toggle source
# File lib/compose_env/context.rb, line 47 def test_method?(method_name) test_methods.include?(method_name) end
test_methods()
click to toggle source
# File lib/compose_env/context.rb, line 55 def test_methods @test_methods ||= env_methods[:test] end