class ActionSet::AttributeValue::PlainRubyAdapter

Public Class Methods

new(raw, target) click to toggle source
# File lib/action_set/attribute_value.rb, line 29
def initialize(raw, target)
  @raw = raw
  @target = target
end

Public Instance Methods

process() click to toggle source
# File lib/action_set/attribute_value.rb, line 34
def process
  return @raw if @raw.is_a? @target

  possible_values.find { |v| v.is_a? @target }
end

Private Instance Methods

possible_typecasters() click to toggle source
# File lib/action_set/attribute_value.rb, line 47
def possible_typecasters
  @possible_typecasters ||= String.instance_methods
                                  .map(&:to_s)
                                  .select { |m| m.start_with? 'to_' }
                                  .reject { |m| %w[to_v8 to_onum].include? m }
end
possible_values() click to toggle source
# File lib/action_set/attribute_value.rb, line 42
def possible_values
  possible_typecasters.map { |m| typecast(m) }
                      .compact
end
typecast(method_name) click to toggle source
# File lib/action_set/attribute_value.rb, line 54
def typecast(method_name)
  @raw.send(method_name)
rescue StandardError
  nil
end