Module: ROM::Options::Transformers

Extended by:
Transproc::Registry
Defined in:
lib/rom/support/options.rb

Overview

Collection of transformers for options

Class Method Summary collapse

Class Method Details

.coercer(_, options, name, fn) ⇒ Object



214
215
216
217
218
# File 'lib/rom/support/options.rb', line 214

def self.coercer(_, options, name, fn)
  return options unless options.key?(name)
  value = options[name]
  options.merge name => fn[value]
end

.default_proc(object, options, name, fn) ⇒ Object



209
210
211
212
# File 'lib/rom/support/options.rb', line 209

def self.default_proc(object, options, name, fn)
  return options if options.key?(name)
  options.merge(name => fn.call(object))
end

.default_value(_, options, name, value) ⇒ Object



204
205
206
207
# File 'lib/rom/support/options.rb', line 204

def self.default_value(_, options, name, value)
  return options if options.key?(name)
  options.merge(name => value)
end

.reader_assigner(object, options, name) ⇒ Object



243
244
245
246
# File 'lib/rom/support/options.rb', line 243

def self.reader_assigner(object, options, name)
  object.instance_variable_set(:"@#{name}", options[name])
  options
end

.type_checker(_, options, name, type) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/rom/support/options.rb', line 220

def self.type_checker(_, options, name, type)
  return options unless options.key?(name)
  value = options[name]

  return options if options[name].is_a?(type)
  fail(
    InvalidOptionValueError,
    "#{name.inspect}:#{value.inspect} has incorrect type" \
    " (#{type} is expected)"
  )
end

.value_checker(_, options, name, list) ⇒ Object



232
233
234
235
236
237
238
239
240
241
# File 'lib/rom/support/options.rb', line 232

def self.value_checker(_, options, name, list)
  return options unless options.key?(name)
  value = options[name]

  return options if list.include?(options[name])
  fail(
    InvalidOptionValueError,
    "#{name.inspect}:#{value.inspect} has incorrect value."
  )
end