Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

Commit

Permalink
Made Pavlov.old_{stuff} use Pavlov.{stuff}
Browse files Browse the repository at this point in the history
  • Loading branch information
markijbema committed Aug 7, 2013
1 parent 3aaa9a9 commit 799d593
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## HEAD

Made `Pavlov.old_command`, `old_query` and `old_interactor` use `Pavlov.command`, `Pavlov.query` and `Pavlov.interactor` so you can upgrade expectations in a forward compatible manner.

## 0.1.4

Added license to gemspec
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## HEAD

* Change your expectations to expect `Pavlov.command` with hash arguments instead of `Pavlov.old_command` with positional arguments. Same for `query` and `interactor`

## 0.1.4

* If you use validations, you must now either use alpha_compatibility, or copy them to your own codebase.
Expand Down
30 changes: 22 additions & 8 deletions lib/pavlov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,36 @@ def self.string_to_classname string
end

def self.command command_name, *args
class_name = 'Commands::' + string_to_classname(command_name)
klass = get_class_by_string(class_name)
klass = class_for_command(command_name)
klass.new(*args).call
end

def self.interactor command_name, *args
class_name = 'Interactors::' + string_to_classname(command_name)
klass = get_class_by_string class_name
def self.interactor interactor_name, *args
klass = class_for_interactor(interactor_name)
klass.new(*args).call
end

def self.query command_name, *args
class_name = 'Queries::' + string_to_classname(command_name)
klass = get_class_by_string class_name
def self.query query_name, *args
klass = class_for_query(query_name)
klass.new(*args).call
end

private

def self.class_for_command command_name
class_name = 'Commands::' + string_to_classname(command_name)
get_class_by_string(class_name)
end

def self.class_for_interactor interactor_name
class_name = 'Interactors::' + string_to_classname(interactor_name)
get_class_by_string(class_name)
end

def self.class_for_query query_name
class_name = 'Queries::' + string_to_classname(query_name)
get_class_by_string(class_name)
end
end

require_relative 'pavlov/engine' if defined?(Rails)
Expand Down
22 changes: 8 additions & 14 deletions lib/pavlov/alpha_compatibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@

module Pavlov
def self.old_command command_name, *args
class_name = 'Commands::' + string_to_classname(command_name)
klass = get_class_by_string(class_name)
attributes = arguments_to_attributes(klass, args)
klass.new(attributes).call
klass = class_for_command(command_name)
command command_name, arguments_to_attributes(klass, args)
end

def self.old_interactor command_name, *args
class_name = 'Interactors::' + string_to_classname(command_name)
klass = get_class_by_string class_name
attributes = arguments_to_attributes(klass, args)
klass.new(attributes).call
def self.old_interactor interactor_name, *args
klass = class_for_interactor(interactor_name)
interactor interactor_name, arguments_to_attributes(klass, args)
end

def self.old_query command_name, *args
class_name = 'Queries::' + string_to_classname(command_name)
klass = get_class_by_string class_name
attributes = arguments_to_attributes(klass, args)
klass.new(attributes).call
def self.old_query query_name, *args
klass = class_for_query(query_name)
query query_name, arguments_to_attributes(klass, args)
end

def self.arguments_to_attributes(operation_class, arguments)
Expand Down
20 changes: 20 additions & 0 deletions spec/integration/alpha_compatibility_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,24 @@ def execute
expect(old_interactor :shouty_greeting).to eq('OHAI, JOHN')
end
end

describe 'old_command style helper' do
before do
stub_const 'Commands::Test', Class.new
class Commands::Test
include Pavlov::Command

arguments :test_string
def execute
end
end
end

it 'redirects to regular Pavlov.command etc' do
Pavlov.should_receive(:command)
.with(:test, test_string: 'test')

old_command :test, 'test'
end
end
end

0 comments on commit 799d593

Please sign in to comment.