Skip to content

Commit

Permalink
Formatting and remove unused lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanrite committed Sep 3, 2023
1 parent 2641687 commit 7565b52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,29 @@ Or install it yourself as:

The main concepts introduced by Operational are:

**Operations** are an orchestrator, or wrapper, around a business process. They don't _do_ a lot themselves but provide a functional interface for executing all the business logic in an action while keeping the data persistence and services objects isolated and decoupled.
**Operations** are an orchestrator, or wrapper, around a business process. They don't _do_ a lot themselves but provide an interface for executing all the business logic in an action while keeping the data persistence and service objects isolated and decoupled.

**Railway Oriented/Monad Programming** is a functional way to define the business logic steps in an action, simplifying the handling of happy paths and failure paths in easy to understand tracks. You define steps that execute in order, the result of the step (truthy or falsey) moves execution to the success or failure tracks.
**Railway Oriented/Monad Programming** is a functional way to define the business logic steps in an action, simplifying the handling of happy paths and failure paths in easy to understand tracks. You define steps that execute in order, the result of the step (truthy or falsey) moves execution to the success or failure tracks. Reduce complicated conditionals with explict methods.

**Functional State** is the idea that each step in an operation receives parameters from the previous step, much like Unix pipe passing output from one command to the next. This state is a single hash that allows you to encapsulate all the information an operation might need, like `current_user`, `params`, or `remote_ip` and provide it in a single point of access. It is mutable within the execution of the operation, so steps may add to it, but immutable at the end of the operation.

**Form Objects** help decouple data persistence from your view. They allow you to define a form or API that may touch many different ActiveRecord models without needing to couple those models together. Validation can be done in the form, where it is more contextually appropriate, rather than on the model. Form Objects more securely define what attributes a request may submit without the need for `StrongParameters`, as they are not directly database backed and do not suffer from mass assignment issues StrongParameters tries to solve.



## Getting Started

Bringing the above concepts to bear, a typical Rails action usnig Operational may look like:
Bringing the above concepts to bear, a typical Rails action using Operational may look like:

```ruby

# app/controllers/todos_controller.rb
class TodosController < ActionController::Base
include Operational::Controller

# By default, params and current_user are set to the state for each operation.
# By default, params and current_user are set to the state for each operation, this can
# be overridden at the controller level.

def new
# Run the "Present" part of the operation, which sets up the model and form.
# Run the Present part of the operation, which typically sets up the model and form.
run Todos::CreateOperation::Present
end

Expand Down Expand Up @@ -86,7 +85,7 @@ end
module Todos
class CreateOperation < Operational::Operation

# Create a model(s), build a form.
# Create a model(s), build a form object.
class Present < Operational::Operation
step :setup_new_model
step Contract::Build(contract: CreateForm, model_key: :todo)
Expand Down Expand Up @@ -118,12 +117,14 @@ module Todos
end
```

_Theres a heck of a lot more, but I'll get to that soon in a proper Wiki._
_Theres a heck of a lot more, but I'll get to that soon in a proper detailed Wiki guide._


## RDocs

To come.


## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bryanrite/operational. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
Expand Down
6 changes: 1 addition & 5 deletions lib/operational/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ def persisted?
end

def other_validators_have_passed?
errors.empty?
end

def validation_errors_exist?
!errors.blank?
errors.blank?
end

protected
Expand Down

0 comments on commit 7565b52

Please sign in to comment.