Skip to content

Commit 4cea655

Browse files
committed
Bump v3.1.0
1 parent 23ad21e commit 4cea655

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [3.1.0] [2018-02-12]
9+
- support `ActiveRecord::Relation` in models (nepalez)
10+
11+
```ruby
12+
param :user, model: User.where(active: true)
13+
```
14+
815
## [3.0.0] [2018-02-01]
916

1017
### Changed
@@ -38,3 +45,4 @@ First public release
3845
[1.0.0]: https://github.com/nepalez/dry-initializer-rails/compare/v0.0.3...v1.0.0
3946
[2.0.0]: https://github.com/nepalez/dry-initializer-rails/compare/v1.0.0...v2.0.0
4047
[3.0.0]: https://github.com/nepalez/dry-initializer-rails/compare/v2.0.0...v3.0.0
48+
[3.1.0]: https://github.com/nepalez/dry-initializer-rails/compare/v3.0.0...v3.1.0

README.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,41 +52,43 @@ class CreateOrder
5252
extend Dry::Initializer
5353

5454
# Params and options
55-
param :customer, model: 'Customer' # use either a name
56-
option :product, model: Product # or a class
55+
param :customer, model: 'Customer' # use either a name
56+
option :product, model: Product # or a class
57+
option :coupon, model: Coupon.where(active: true) # or relation
5758

5859
def call
59-
Order.create customer: customer, product: product
60+
Order.create customer: customer, product: product, coupon: coupon
6061
end
6162
end
6263
```
6364

6465
Now you can assign values as pre-initialized model instances:
6566

6667
```ruby
67-
customer = Customer.find(1)
68-
product = Product.find(2)
69-
70-
order = CreateOrder.new(customer, product: product).call
71-
order.customer # => <Customer @id=1 ...>
72-
order.product # => <Product @id=2 ...>
68+
customer = Customer.create(id: 1)
69+
product = Product.create(id: 2)
70+
coupon = Coupon.create(id: 3, active: true)
71+
72+
order = CreateOrder.new(customer, product: product, coupon: coupon).call
73+
order.customer # => #<Customer @id=1 ...>
74+
order.product # => #<Product @id=2 ...>
75+
order.coupon # => #<Coupon @id=3 ...>
7376
```
7477

7578
...or their ids:
7679

7780
```ruby
78-
order = CreateOrder.new(1, product: 2).call
79-
order.customer # => <Customer @id=1 ...>
80-
order.product # => <Product @id=2 ...>
81+
order = CreateOrder.new(1, product: 2, coupon: 3).call
82+
order.customer # => #<Customer @id=1 ...>
83+
order.product # => #<Product @id=2 ...>
84+
order.coupon # => #<Coupon @id=3 ...>
8185
```
8286

83-
The instance is envoked using method `find_by(id: ...)`.
84-
With wrong ids `nil` values are assigned to a corresponding params and options:
87+
The instance is envoked using method `find_by!(id: ...)`.
8588

8689
```ruby
87-
order = CreateOrder.new(0, product: 0).call
88-
order.customer # => nil
89-
order.product # => nil
90+
order = CreateOrder.new(1, product: 2, coupon: 4).call
91+
# raises #<ActiveRecord::RecordNotFound>
9092
```
9193

9294
You can specify custom `key` for searching model instance:

dry-initializer-rails.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |gem|
22
gem.name = "dry-initializer-rails"
3-
gem.version = "3.0.0"
3+
gem.version = "3.1.0"
44
gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
55
gem.email = ["andrew.kozin@gmail.com"]
66
gem.homepage = "https://github.com/nepalez/dry-initializer-rails"

0 commit comments

Comments
 (0)