Sha256: a0cab959a941d46b7b47a31976bc9c094e1cf0e3e9f9b1cf630bceeac45aabc5
Contents?: true
Size: 1.16 KB
Versions: 10
Compression:
Stored size: 1.16 KB
Contents
# encoding: utf-8 module Hexx # Declares the +attr_coerced+ private class method. # # @example # # require "hexx" # require_relative "attributes/string" # # class User # extend Hexx::Models # attr_coerced :name, type: ActiveSupport::Multibyte::Chars # end # # # This will coerce user name with mb chars: # user = User.new name: "Иоанн" # user.name # # => #<ActiveSupport::Multibyte::Chars @wrapped_string = "Иоанн"> module Models private # @!method attr_coerced(*names, options) # Coerced the attribute(s) with given type. # @example (see Hexx::Models) # @param [Array<Symbol, String>] names The list of attributes to be coerced. # @param [Hash] options The coersion options. # @option options [Class] :type The class for coersion. def attr_coerced(*names, type:) names.each { |name| coercer.new(self, name, type).coerce } end # @api hide # Applied coercer for attributes. # @note The method is reloaded in the 'hexx-active_record' gem to allow # coersion of ActiveRecord models' attributes. def coercer @coercer ||= BaseCoercer end end end
Version data entries
10 entries across 10 versions & 1 rubygems