Sha256: d0dbc7bfd5978044249a6b5cb27e6e860ec47b1a66bd1542a5fd180ab3a0d335

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'active_record'
require 'declare_schema/dsl'
require 'declare_schema/model'
require 'declare_schema/field_declaration_dsl'

module DeclareSchema
  module Macros
    def fields(table_options = {}, &block)
      # Any model that calls 'fields' gets DeclareSchema::Model behavior
      DeclareSchema::Model.mix_in(self)

      @include_in_migration = true
      @table_options        = table_options

      if block
        dsl = DeclareSchema::FieldDeclarationDsl.new(self)
        if block.arity == 1
          yield dsl
        else
          dsl.instance_eval(&block)
        end
      end
    end
    deprecate :fields, deprecator: ActiveSupport::Deprecation.new('1.0', 'DeclareSchema')

    def declare_schema(table_options = {}, &block)
      # Any model that calls 'fields' gets DeclareSchema::Model behavior
      DeclareSchema::Model.mix_in(self)

      # @include_in_migration = false #||= options.fetch(:include_in_migration, true); options.delete(:include_in_migration)
      @include_in_migration = true # TODO: Add back or delete the include_in_migration feature
      @table_options        = table_options

      if block
        dsl = DeclareSchema::Dsl.new(self, null: false)
        if block.arity == 1
          yield dsl
        else
          dsl.instance_eval(&block)
        end
      end
    end
  end
end

ActiveRecord::Base.singleton_class.prepend DeclareSchema::Macros

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
declare_schema-0.11.1 lib/declare_schema/extensions/active_record/fields_declaration.rb
declare_schema-0.11.0 lib/declare_schema/extensions/active_record/fields_declaration.rb
declare_schema-0.10.1 lib/declare_schema/extensions/active_record/fields_declaration.rb
declare_schema-0.10.0 lib/declare_schema/extensions/active_record/fields_declaration.rb
declare_schema-0.10.0.pre.dc.1 lib/declare_schema/extensions/active_record/fields_declaration.rb