Sha256: 821b810ecc086ea17f3c450d2b46fd8349538ea9995c5eb8cbb965fe4bfe7e32

Contents?: true

Size: 1.02 KB

Versions: 5

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Clowne
  module Adapters
    # Extend ActiveRecord with Clowne DSL and methods
    module ActiveRecordDSL
      module InstanceMethods # :nodoc:
        # Shortcut to call class's cloner call with self
        def clowne(*args, &block)
          self.class.cloner_class.call(self, *args, &block)
        end
      end

      module ClassMethods # :nodoc:
        def clowne_config(options = {}, &block)
          if options.delete(:inherit) != false && superclass.respond_to?(:cloner_class)
            parent_cloner = superclass.cloner_class
          end

          parent_cloner ||= Clowne::Cloner
          cloner = instance_variable_set(:@_clowne_cloner, Class.new(parent_cloner))
          cloner.adapter :active_record
          cloner.instance_exec(&block)
        end
      end
    end
  end
end

ActiveSupport.on_load(:active_record) do
  ::ActiveRecord::Base.extend Clowne::Adapters::ActiveRecordDSL::ClassMethods
  ::ActiveRecord::Base.include Clowne::Adapters::ActiveRecordDSL::InstanceMethods
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
clowne-1.2.0 lib/clowne/adapters/active_record/dsl.rb
clowne-1.1.0 lib/clowne/adapters/active_record/dsl.rb
clowne-1.0.0 lib/clowne/adapters/active_record/dsl.rb
clowne-0.2.0 lib/clowne/adapters/active_record/dsl.rb
clowne-0.1.0 lib/clowne/adapters/active_record/dsl.rb