module Wardrobe::Plugins::Coercible::Refinements

Constants

FALSE_STRINGS
HASH_SINGLETON_MODIFIER
TRUE_STRINGS

Public Instance Methods

coerce(v, _atr) click to toggle source
# File lib/wardrobe/plugins/coercible/refinements/array.rb, line 8
def coerce(v, _atr)
  case v
  when self     then v
  when Set      then v.to_a
  when NilClass then []
  else
    raise UnsupportedError
  end
end
coerce_hash(h, atr) click to toggle source
# File lib/wardrobe/plugins/coercible/refinements/hash.rb, line 52
def coerce_hash(h, atr)
  hash = h.map do |key, value|
    #TODO: Since we pass around the atr object, how should this work here? Just pass nil?
    [self.first[0].coerce(key, nil), self.first[1].coerce(value, nil)]
  end.to_h

  hash.singleton_class.class_exec(first,atr, &HASH_SINGLETON_MODIFIER)
  hash
end
integer(v) click to toggle source
# File lib/wardrobe/plugins/coercible/refinements/boolean.rb, line 21
def integer(v)
  return false if v == 0
  return true if v == 1
  raise UnsupportedError
end
string(v) click to toggle source
# File lib/wardrobe/plugins/coercible/refinements/boolean.rb, line 27
def string(v)
  return false if FALSE_STRINGS.include?(v)
  return true if TRUE_STRINGS.include?(v)
  raise UnsupportedError
end