Sha256: c745985c9f2fc7d7766919263e918be76b5a3377b395ad06f899a638900b4af0

Contents?: true

Size: 780 Bytes

Versions: 2

Compression:

Stored size: 780 Bytes

Contents

# frozen_string_literal: true
# require_relative "phonofy/fy/version"

module Phonofy
  module Model
    module ClassMethods

      DEFAULTS = { phonelib: { allow_blank: true, validation_options: {} } }.freeze

      def phonofy(column_name = :phone_number, **options)
        options = DEFAULTS.deep_merge(options)

        unless respond_to? :phonofy_configs
          class_attribute :phonofy_configs
          self.phonofy_configs = { _counter: {} }
        end

        counter                                 = (phonofy_configs[:_counter][column_name] ||= 0)
        phonofy_configs[:_counter][column_name] += 1

        phonofy_configs["#{column_name}_#{counter}"] = options.dup

        include InstanceDynamicMethods.new(column_name, options)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
phonofy-0.1.2 lib/model/class_methods.rb
phonofy-0.1.1 lib/model/class_methods.rb