Class: Settable::Setting

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

Overview

Private: Wrapper around our settings.

Instance Method Summary collapse

Constructor Details

#initialize(namespace, key, value, &block) ⇒ Setting

Public: Create a new setting.

namespace - The namespace to create this setting in. key - The setting name. value - The value to return for this setting (if not block given). block - The block to run when this setting is retrieved.

Examples

setting = Setting.new(namespace, :hello, 'world')
setting.value
# => 'world'

setting = Setting.new(namespace, :hello){ 'ohai' }
setting.value
# => 'ohai'

Returns the setting object.



213
214
215
216
217
# File 'lib/settable.rb', line 213

def initialize(namespace, key, value, &block)
  @key = key
  value = SettingBlock.new(namespace, &block) if block_given?
  @value = value
end

Instance Method Details

#present?Boolean

Public: Presence method for the setting. Returns the truthiness of the value.

Returns:

  • (Boolean)


234
235
236
# File 'lib/settable.rb', line 234

def present?
  !!value
end

#valueObject

Public: Retrieve the settings value. If a block was given in the

constructor, it runs the block - otherwise it will return
the value given in the constructor.

Returns the value.



224
225
226
227
228
229
230
# File 'lib/settable.rb', line 224

def value
  if @value.respond_to?(:call)
    @value.call
  else
    @value
  end
end