Class: Settable::SettingBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/settable.rb

Overview

Private: Wrapper around the setting’s value. Returns the wrapped value.

Instance Method Summary collapse

Constructor Details

#initialize(namespace, &block) ⇒ SettingBlock

Public: Create a setting block in the given namespace.

namespace - The namespace to operate in. block - The block to call when retrieving the setting.

Returns the setting value block.



122
123
124
125
126
# File 'lib/settable.rb', line 122

def initialize(namespace, &block)
  @block = lambda &block
  @namespace = namespace
  @environment = namespace.environment
end

Instance Method Details

#callObject

Public: Retrieve the value from this block, if we are using environment

checkers then we will check the environment and override any
default values

Returns the value for the setting.



133
134
135
136
137
# File 'lib/settable.rb', line 133

def call
  @__env_return_value__ = nil # avoid using throw/catch
  default_return_value = instance_eval &@block
  @__env_return_value__ || default_return_value
end