Sha256: cddae6bbfd7886388770a2a4800123c1f5880c518ad5faaabaafdc523877b4af

Contents?: true

Size: 1.49 KB

Versions: 17

Compression:

Stored size: 1.49 KB

Contents

RSpec.shared_context 'plugins' do
  before do
    module Test
      class WrappingInput
        def initialize(input)
          @input = input || Hash
        end
      end

      module Timestamps
        class InputWithTimestamp < WrappingInput
          def [](value)
            v = @input[value]
            now = Time.now

            if v[:created_at]
              v.merge(updated_at: now)
            else
              v.merge(created_at: now, updated_at: now)
            end
          end
        end

        module ClassInterface
          def build(relation, options = {})
            super(relation, options.merge(input: InputWithTimestamp.new(input)))
          end
        end

        def self.included(klass)
          super

          klass.extend ClassInterface
        end
      end

      module UpcaseName
        class UpcaseNameInput < WrappingInput
          def [](value)
            v = @input[value]
            v.merge(name: value.fetch(:name).upcase)
          end
        end

        module ClassInterface
          def build(relation, options = {})
            super(relation, options.merge(input: UpcaseNameInput.new(options.fetch(:input))))
          end
        end

        def self.included(klass)
          super

          klass.extend ClassInterface
        end
      end
    end

    ROM.plugins do
      adapter :sql do
        register :timestamps, Test::Timestamps, type: :command
        register :upcase_name, Test::UpcaseName, type: :command
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rom-repository-1.4.0 spec/shared/plugins.rb
rom-repository-1.3.3 spec/shared/plugins.rb
rom-repository-1.3.2 spec/shared/plugins.rb
rom-repository-1.3.1 spec/shared/plugins.rb
rom-repository-1.3.0 spec/shared/plugins.rb
rom-repository-1.2.0 spec/shared/plugins.rb
rom-repository-1.1.0 spec/shared/plugins.rb
rom-repository-1.0.2 spec/shared/plugins.rb
rom-repository-1.0.1 spec/shared/plugins.rb
rom-repository-1.0.0 spec/shared/plugins.rb
rom-repository-1.0.0.rc2 spec/shared/plugins.rb
rom-repository-1.0.0.rc1 spec/shared/plugins.rb
rom-repository-1.0.0.beta3 spec/shared/plugins.rb
rom-repository-1.0.0.beta2 spec/shared/plugins.rb
rom-repository-1.0.0.beta1 spec/shared/plugins.rb
rom-repository-0.3.1 spec/shared/plugins.rb
rom-repository-0.3.0 spec/shared/plugins.rb