Method: Ektoplayer::Config#set

Defined in:
lib/ektoplayer/config.rb

#set(option, value) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/ektoplayer/config.rb', line 231

def set(option, value)
   option = option.to_sym
   current_value = get(option)

   if cast = @cast[option]
      @options[option] = cast.call(value)
   else
      if current_value.is_a?Integer
         @options[option] = Integer(value)
      elsif current_value.is_a?Float
         @options[option] = Float(value)
      elsif current_value.is_a?TrueClass or current_value.is_a?FalseClass
         fail 'invalid bool' unless %w(true false).include? value
         @options[option] = (value == 'true')
      else
         @options[option] = value
      end
   end

   @options[option].freeze
rescue
   fail "Invalid value '#{value}' for '#{option}': #{$!}"
end