Sha256: ad87c03dc2c0a1971f8496ca7b016340db14e9dd3568e3b7c175b941d7af525b

Contents?: true

Size: 582 Bytes

Versions: 10

Compression:

Stored size: 582 Bytes

Contents

module Toy
  module Inheritance
    extend ActiveSupport::Concern

    module ClassMethods
      DuplicatedInstanceVariables = [
        :attributes,
        :key_factory,
        :lists,
        :references,
        :adapter,
      ]

      def inherited(subclass)
        DuplicatedInstanceVariables.each do |name|
          subclass.instance_variable_set("@#{name}", send(name).dup) if respond_to?(name)
        end

        subclass.attribute(:type, String, :default => subclass.name)

        super
      end
    end

    def type
      read_attribute(:type)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
toystore-0.13.2 lib/toy/inheritance.rb
toystore-0.13.1 lib/toy/inheritance.rb
toystore-0.13.0 lib/toy/inheritance.rb
toystore-0.12.0 lib/toy/inheritance.rb
toystore-0.11.0 lib/toy/inheritance.rb
toystore-0.10.4 lib/toy/inheritance.rb
toystore-0.10.3 lib/toy/inheritance.rb
toystore-0.10.2 lib/toy/inheritance.rb
toystore-0.10.1 lib/toy/inheritance.rb
toystore-0.10.0 lib/toy/inheritance.rb