Sha256: ace9c629a053b7c47ea4b3069af82037a04983ecce51ab67efedeee267f53e63

Contents?: true

Size: 862 Bytes

Versions: 1

Compression:

Stored size: 862 Bytes

Contents

module AxleAttributes
  module Serializations
    class Reflection
      attr_accessor :macro, :name, :options
      def initialize(macro, name, options)
        @macro      = macro
        @name       = name.to_sym
        @options    = options
        @collection = macro == :serialize_many
      end

      def serialization_class
        case macro
        when :serialize_many
          Serializations::SerializeMany
        when :serialize_one
          Serializations::SerializeOne
        end
      end

      def storage_column
        name
      end

      def counter_cache_column
        unless options[:counter_cache] == false
          "#{name}_count"
        end
      end

      def klass
        @klass ||= (options[:class_name] || name.to_s.classify).constantize
      end

      def collection?
        @collection
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
axle_attributes-1.13.2 lib/axle_attributes/serializations/reflection.rb