README.md in pragma-2.1.1 vs README.md in pragma-2.2.0
- old
+ new
@@ -165,11 +165,11 @@
module V1
module Article
module Operation
class Create < Pragma::Operation::Base
# Let the macro figure out class names.
- step Pragma::Operation::Macro::Classes()
+ step Pragma::Macro::Classes()
step :execute!
# But override the contract.
self['contract.default.class'] = Contract::CustomCreate
@@ -209,11 +209,11 @@
module Operation
class Create < Pragma::Operation::Base
# This step can be done by Classes if you want.
self['model.class'] = ::Article
- step Pragma::Operation::Macro::Model(:build)
+ step Pragma::Macro::Model(:build)
step :save!
def save!(options)
# Here you'd usually validate and assign parameters before saving.
@@ -237,11 +237,11 @@
module Operation
class Show < Pragma::Operation::Base
# This step can be done by Classes if you want.
self['model.class'] = ::Article
- step Pragma::Operation::Macro::Model(:find_by), fail_fast: true
+ step Pragma::Macro::Model(:find_by), fail_fast: true
step :respond!
def respond!(options)
options['result.response'] = Response::Ok.new(
entity: options['model']
@@ -274,11 +274,13 @@
class Show < Pragma::Operation::Base
# This step can be done by Classes if you want.
self['policy.default.class'] = Policy
step :model!
- step Pragma::Operation::Macro::Policy(), fail_fast: true
+ step Pragma::Macro::Policy(), fail_fast: true
+ # You can also specify a custom method to call on the policy:
+ # step Pragma::Macro::Policy(action: :custom_method), fail_fast: true
step :respond!
def model!(params:, **)
options['model'] = ::Article.find(params[:id])
end
@@ -306,16 +308,16 @@
module V1
module Article
module Operation
class Index < Pragma::Operation::Base
step :model!
- step Pragma::Operation::Macro::Filtering()
+ step Pragma::Macro::Filtering()
step :respond!
self['filtering.filters'] = [
- Pragma::Operation::Filter::Equals.new(param: :by_category, column: :category_id),
- Pragma::Operation::Filter::Ilike.new(param: :by_title, column: :title)
+ Pragma::Filter::Equals.new(param: :by_category, column: :category_id),
+ Pragma::Filter::Ilike.new(param: :by_title, column: :title)
]
def model!(params:, **)
options['model'] = ::Article.all
end
@@ -324,17 +326,22 @@
end
end
end
```
-With the example above, you are exposing the `by_category` filter and the `by_title` filters. The
-following filters are available for ActiveRecord currently:
+With the example above, you are exposing the `by_category` filter and the `by_title` filters.
-- `Equals`: performs an equality (`=`) comparison.
-- `Like`: performs a `LIKE` comparison.
-- `Ilike`: performs an `ILIKE` comparison.
+The following filters are available for ActiveRecord currently:
+- `Equals`: performs an equality (`=`) comparison (requires `:column`)-
+- `Like`: performs a `LIKE` comparison (requires `:column`).
+- `Ilike`: performs an `ILIKE` comparison (requires `:column`).
+- `Where`: adds a generic `WHERE` clause (requires `:condition` and passes the parameter's value as
+ `:value`).
+- `Scope`: calls a method on the collection (requires `:scope` and passes the parameter's value as
+ the first argument).
+
Support for more clauses as well as more ORMs will come soon.
### Ordering
**Used in:** Index
@@ -358,11 +365,11 @@
self['ordering.columns'] = %i[title published_at updated_at]
step :model!
# This will override `model` with the ordered relation.
- step Pragma::Operation::Macro::Ordering(), fail_fast: true
+ step Pragma::Macro::Ordering(), fail_fast: true
step :respond!
def model!(options)
options['model'] = options['model.class'].all
@@ -410,11 +417,11 @@
self['model.class'] = ::Article
step :model!
# This will override `model` with the paginated relation.
- step Pragma::Operation::Macro::Pagination(), fail_fast: true
+ step Pragma::Macro::Pagination(), fail_fast: true
step :respond!
def model!(options)
options['model'] = options['model.class'].all
@@ -466,10 +473,10 @@
class Show < Pragma::Operation::Base
# This step can be done by Classes if you want.
self['decorator.instance.class'] = Decorator::Instance
step :model!
- step Pragma::Operation::Macro::Decorator(), fail_fast: true
+ step Pragma::Macro::Decorator(), fail_fast: true
step :respond!
def model!(params:, **)
options['model'] = ::Article.find(params[:id])
end