Sha256: 7b8193f6a42e8034735b16e8b8db40469b198efbb24727cde71361e3512552ae

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true
require_relative "attributes"

module ActiveMocker
  class MockCreator
    module ClassMethods
      include Attributes

      def attributes_with_defaults
        types_hash
        attributes.each_with_object({}) do |attr, hash|
          hash[attr.name] = attr.default
        end
      end

      def types_hash
        @types_hash ||= attributes.each_with_object(HashNewStyle.new) do |attr, types|
          types[attr.name] = attr.type.to_s
        end.inspect
      end

      def associations
        @associations ||= schema_scrapper.associations.to_a.each_with_object({}) do |a, h|
          h[a.name] = nil
        end
      end

      def associations_by_class
        schema_scrapper.associations.to_a.each_with_object({}) do |r, hash|
          hash[r.class_name.to_s]         ||= {}
          hash[r.class_name.to_s][r.type] ||= []
          hash[r.class_name.to_s][r.type] << r.name
        end
      end

      def attribute_names
        attributes.map(&:name)
      end

      def abstract_class
        schema_scrapper.abstract_class?
      end

      def table_name
        schema_scrapper.table_name
      end

      def mocked_class
        [nested_modules, class_name].compact.reject(&:empty?).join("::")
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
active_mocker-2.6.2 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.6.1.beta2 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.6.1.beta lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.6.0 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.5.4 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.5.3 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.5.2 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.5.1 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.5.1.pre lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.5.0 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.4.4 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.4.3 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.4.2 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.4.1 lib/active_mocker/mock_creator/class_methods.rb
active_mocker-2.4.0 lib/active_mocker/mock_creator/class_methods.rb