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.



208
209
210
211
212
# File 'lib/settable.rb', line 208

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)


229
230
231
# File 'lib/settable.rb', line 229

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.



219
220
221
222
223
224
225
# File 'lib/settable.rb', line 219

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