Module: ClassX::AttributeMethods::ClassMethods::CoerceWithArray

Defined in:
lib/classx/attribute.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#coerce(val) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/classx/attribute.rb', line 54

def coerce val
  result = val
  config[:coerce].each do |item|
    raise unless item.kind_of? Hash

    case item
    when Hash
      item.each do |cond, rule|
        case cond
        when Proc
          if cond.call(val)
            result = rule.call(val)
            break
          end
        end

        break if result
      end
    end

    break if result
  end

  return result
end