diff --git a/CHANGELOG.md b/CHANGELOG.md index 8174d3b..3322257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ # Pavlov Changelog -## HEAD +## 0.3.0 + +#### Removed + +* Removed `Pavlov::Interactor`, `Pavlov::Command` and `Pavlov::Query` in favor of generated classes inside your own + application. Run `rails generate pavlov:install` and then find-and-replace `\n\s+include Pavlov::` for ` < ` to + rewrite your operations so that they inherit from the generated classes. + +## 0.2.0 This release brings forth lots and lots of incompatibilities. Where possible, we've tried to keep a backwards-compatible API available. You can activate this by requiring `pavlov/alpha_compatibility'. diff --git a/README.md b/README.md index 814eac1..21b0d4f 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,7 @@ Then generate some initial files with: ## Usage ```ruby -class Commands::CreateBlogPost - include Pavlov::Command +class Commands::CreateBlogPost < Command attribute :id, Integer attribute :title, String @@ -40,8 +39,7 @@ class Commands::CreateBlogPost end end -class Queries::AvailableId - include Pavlov::Query +class Queries::AvailableId < Query private @@ -54,8 +52,7 @@ class Queries::AvailableId end end -class Interactors::CreateBlogPost - include Pavlov::Interactor +class Interactors::CreateBlogPost < Interactor attribute :title, String attribute :body, String @@ -117,8 +114,7 @@ Interactors must define a method `authorized?` that determines if the interactio To help you determine whether operations are allowed, you can set up a global [interaction context](#context), which you can then access from your interactors: ```ruby -class Interactors::CreateBlogPost - include Pavlov::Interactor +class Interactors::CreateBlogPost < Interactor def authorized? context.current_user.is_admin? diff --git a/lib/pavlov.rb b/lib/pavlov.rb index cd2807f..ad392ce 100644 --- a/lib/pavlov.rb +++ b/lib/pavlov.rb @@ -34,8 +34,5 @@ def self.query command_name, *args require_relative 'pavlov/validation_error' require_relative 'pavlov/validations' require_relative 'pavlov/operation' -require_relative 'pavlov/command' -require_relative 'pavlov/query' -require_relative 'pavlov/interactor' require_relative 'pavlov/version' require_relative 'pavlov/alpha_compatibility' diff --git a/lib/pavlov/command.rb b/lib/pavlov/command.rb deleted file mode 100644 index 8de834e..0000000 --- a/lib/pavlov/command.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'active_support/concern' -require_relative 'operation' - -module Pavlov - module Command - extend ActiveSupport::Concern - include Pavlov::Operation - end -end diff --git a/lib/pavlov/interactor.rb b/lib/pavlov/interactor.rb deleted file mode 100644 index 6656ee5..0000000 --- a/lib/pavlov/interactor.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'active_support/concern' -require 'active_support/inflector' -require 'pavlov/operation' - -module Pavlov - module Interactor - extend ActiveSupport::Concern - include Pavlov::Operation - - module ClassMethods - # make our interactors behave as Resque jobs - def perform(*args) - new(*args).call - end - - def queue - @queue ||= :interactor_operations - end - end - - def authorized? - raise NotImplementedError - end - end -end diff --git a/lib/pavlov/query.rb b/lib/pavlov/query.rb deleted file mode 100644 index 39a1ef2..0000000 --- a/lib/pavlov/query.rb +++ /dev/null @@ -1,9 +0,0 @@ -require 'active_support/concern' -require_relative 'operation' - -module Pavlov - module Query - extend ActiveSupport::Concern - include Pavlov::Operation - end -end diff --git a/spec/integration/alpha_compatibility_spec.rb b/spec/integration/alpha_compatibility_spec.rb index 8698eae..ecdf2d3 100644 --- a/spec/integration/alpha_compatibility_spec.rb +++ b/spec/integration/alpha_compatibility_spec.rb @@ -2,6 +2,10 @@ require 'pavlov' require 'pavlov/alpha_compatibility' +require 'generators/pavlov/templates/backend/command' +require 'generators/pavlov/templates/backend/query' +require 'generators/pavlov/templates/backend/interactor' + describe "Pavlov Alpha Compatibility" do include Pavlov::Helpers @@ -9,8 +13,7 @@ before do stub_const "Interactors", Module.new - class Interactors::OldStyleInteractor - include Pavlov::Interactor + class Interactors::OldStyleInteractor < Interactor arguments :title, :published def authorized? @@ -38,8 +41,7 @@ def pavlov_options before do stub_const "Queries", Module.new stub_const "Interactors", Module.new - class Queries::FindUppercaseName - include Pavlov::Query + class Queries::FindUppercaseName < Query attribute :pavlov_options, Hash, default: {} @@ -48,8 +50,7 @@ def execute end end - class Interactors::ShoutyGreeting - include Pavlov::Interactor + class Interactors::ShoutyGreeting < Interactor attribute :pavlov_options, Hash, default: {} diff --git a/spec/integration/attributes_spec.rb b/spec/integration/attributes_spec.rb index c274c0d..5b0fc96 100644 --- a/spec/integration/attributes_spec.rb +++ b/spec/integration/attributes_spec.rb @@ -1,12 +1,15 @@ require_relative '../spec_helper' require 'pavlov' +require 'generators/pavlov/templates/backend/command' +require 'generators/pavlov/templates/backend/query' +require 'generators/pavlov/templates/backend/interactor' + describe "Pavlov attributes" do before do stub_const "Interactors", Module.new module Interactors - class CreateBlogPost - include Pavlov::Interactor + class CreateBlogPost < Interactor attribute :title, String attribute :published, Boolean, default: true diff --git a/spec/pavlov/command_spec.rb b/spec/pavlov/command_spec.rb deleted file mode 100644 index 762ace1..0000000 --- a/spec/pavlov/command_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../spec_helper' -require 'pavlov/command' - -describe Pavlov::Command do - let 'command_with_private_authorized?' do - Class.new do - include Pavlov::Command - - private - def authorized? - false - end - end - end - - it "raises an error when private .authorized? returns false" do - expect do - command_with_private_authorized?.new.call - end.to raise_error(Pavlov::AccessDenied) - end -end diff --git a/spec/pavlov/interactor_spec.rb b/spec/pavlov/interactor_spec.rb deleted file mode 100644 index 2ce5921..0000000 --- a/spec/pavlov/interactor_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require_relative '../spec_helper' -require 'pavlov/interactor' - -describe Pavlov::Interactor do - let 'interactor_without_authorized?' do - Class.new do - include Pavlov::Interactor - end - end - - it "raises an error when .authorized? does not exist" do - expect { - interactor_without_authorized?.new.call - }.to raise_error(NotImplementedError) - end - - let 'interactor_with_private_authorized?' do - Class.new do - include Pavlov::Interactor - - private - def authorized? - false - end - end - end - - it "raises an error when private .authorized? returns false" do - expect { - interactor_with_private_authorized?.new.call - }.to raise_error(Pavlov::AccessDenied) - end -end diff --git a/spec/pavlov/query_spec.rb b/spec/pavlov/query_spec.rb deleted file mode 100644 index 2ca16b3..0000000 --- a/spec/pavlov/query_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../spec_helper' -require 'pavlov/query' - -describe Pavlov::Query do - let 'qeury_with_private_authorized?' do - Class.new do - include Pavlov::Query - - private - def authorized? - false - end - end - end - - it "raises an error when private .authorized? does not exist" do - expect do - qeury_with_private_authorized?.new.call - end.to raise_error(Pavlov::AccessDenied) - end -end