dry-initializer-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +14 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.rubocop.yml +91 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +9 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/Rakefile +13 -0
- data/dry-initializer-rails.gemspec +23 -0
- data/lib/dry/initializer/rails/model.rb +25 -0
- data/lib/dry/initializer/rails.rb +13 -0
- data/lib/dry-initializer-rails.rb +1 -0
- data/spec/dry/initializer/assignment_by_custom_key_spec.rb +60 -0
- data/spec/dry/initializer/assignment_by_id_spec.rb +28 -0
- data/spec/dry/initializer/assignment_by_model_spec.rb +21 -0
- data/spec/dry/initializer/base_syntax_spec.rb +22 -0
- data/spec/dummy/Rakefile +14 -0
- data/spec/dummy/app/models/item.rb +2 -0
- data/spec/dummy/app/models/user.rb +2 -0
- data/spec/dummy/config/database.yml +6 -0
- data/spec/dummy/config/environment.rb +10 -0
- data/spec/dummy/db/migrate/20160509134800_create_users.rb +7 -0
- data/spec/dummy/db/migrate/20160509134900_create_items.rb +7 -0
- data/spec/dummy/db/schema.rb +28 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/dummy/application.rb +26 -0
- data/spec/dummy/lib/dummy.rb +9 -0
- data/spec/spec_helper.rb +21 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3843932bc46473f1556168bb6bc2af64ad1ca450
|
4
|
+
data.tar.gz: 5fecb6546078b4a3754aab3ad69d9ae855888120
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7979963d78f8daa321a8974ad734b737fe36acfc44d9cf3affbac35d4168452b7e183a91403fc68688b1b8ce45e86bba7644318d56873d088481714377bd5fe7
|
7
|
+
data.tar.gz: 7e9c589aa160cba362dc728f4ea7291fd97dea0b0814d03abe8eeaaacc460d6810fae2aaac598929fac301b2c74d85e01c0c52c90c1dcf5f267ce10d7f761403
|
data/.codeclimate.yml
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
StyleGuideCopsOnly: true
|
6
|
+
TargetRubyVersion: 2.2
|
7
|
+
|
8
|
+
Lint/HandleExceptions:
|
9
|
+
Exclude:
|
10
|
+
- '**/*_spec.rb'
|
11
|
+
|
12
|
+
Lint/RescueException:
|
13
|
+
Exclude:
|
14
|
+
- '**/*_spec.rb'
|
15
|
+
|
16
|
+
Metrics/LineLength:
|
17
|
+
Max: 80
|
18
|
+
Exclude:
|
19
|
+
- 'spec/**/*.rb'
|
20
|
+
|
21
|
+
Style/AccessorMethodName:
|
22
|
+
Exclude:
|
23
|
+
- '**/*_spec.rb'
|
24
|
+
|
25
|
+
Style/Alias:
|
26
|
+
EnforcedStyle: prefer_alias_method
|
27
|
+
|
28
|
+
Style/AsciiComments:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/CaseEquality:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/ClassAndModuleChildren:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Style/DoubleNegation:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/EmptyLinesAroundClassBody:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/EmptyLinesAroundModuleBody:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Style/EmptyLineBetweenDefs:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Style/FileName:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Style/ModuleFunction:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Style/RaiseArgs:
|
59
|
+
EnforcedStyle: compact
|
60
|
+
|
61
|
+
Style/Semicolon:
|
62
|
+
Exclude:
|
63
|
+
- '**/*_spec.rb'
|
64
|
+
|
65
|
+
Style/SignalException:
|
66
|
+
EnforcedStyle: semantic
|
67
|
+
|
68
|
+
Style/SingleLineBlockParams:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Style/SingleLineMethods:
|
72
|
+
Exclude:
|
73
|
+
- '**/*_spec.rb'
|
74
|
+
|
75
|
+
Style/SpaceBeforeFirstArg:
|
76
|
+
Enabled: false
|
77
|
+
|
78
|
+
Style/SpecialGlobalVars:
|
79
|
+
Exclude:
|
80
|
+
- '**/Gemfile'
|
81
|
+
- '**/*.gemspec'
|
82
|
+
|
83
|
+
Style/StringLiterals:
|
84
|
+
EnforcedStyle: double_quotes
|
85
|
+
|
86
|
+
Style/StringLiteralsInInterpolation:
|
87
|
+
EnforcedStyle: double_quotes
|
88
|
+
|
89
|
+
Style/TrivialAccessors:
|
90
|
+
Exclude:
|
91
|
+
- '**/*_spec.rb'
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Andrew Kozin (nepalez), Vladimir Kochnev (marshall-lee)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# dry-initializer-rails [![Join the chat at https://gitter.im/dry-rb/chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dry-rb/chat)
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/dry-initializer-rails.svg)][gem]
|
4
|
+
[![Build Status](https://travis-ci.org/dry-rb/dry-initializer-rails.svg?branch=master)][travis]
|
5
|
+
[![Dependency Status](https://gemnasium.com/dry-rb/dry-initializer-rails.svg)][gemnasium]
|
6
|
+
[![Code Climate](https://codeclimate.com/github/dry-rb/dry-initializer-rails/badges/gpa.svg)][codeclimate]
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/dry-rb/dry-initializer-rails/badges/coverage.svg)][coveralls]
|
8
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-initializer-rails.svg?branch=master)][inchpages]
|
9
|
+
|
10
|
+
[gem]: https://rubygems.org/gems/dry-initializer-rails
|
11
|
+
[travis]: https://travis-ci.org/dry-rb/dry-initializer-rails
|
12
|
+
[gemnasium]: https://gemnasium.com/dry-rb/dry-initializer-rails
|
13
|
+
[codeclimate]: https://codeclimate.com/github/dry-rb/dry-initializer-rails
|
14
|
+
[coveralls]: https://coveralls.io/r/dry-rb/dry-initializer-rails
|
15
|
+
[inchpages]: http://inch-ci.org/github/dry-rb/dry-initializer-rails
|
16
|
+
|
17
|
+
Rails plugin to [dry-initializer][dry-initializer]
|
18
|
+
|
19
|
+
[dry-initializer]: https://github.com/dry-rb/dry-initializer
|
20
|
+
|
21
|
+
## Installation
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'dry-initializer-rails'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
```shell
|
32
|
+
$ bundle
|
33
|
+
```
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
```shell
|
38
|
+
$ gem install dry-initializer-rails
|
39
|
+
```
|
40
|
+
|
41
|
+
## Synopsis
|
42
|
+
|
43
|
+
The gem provides value coercion to ActiveRecord instances.
|
44
|
+
|
45
|
+
Add the `:model` setting to `param` or `option`:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
require 'dry-initializer'
|
49
|
+
require 'dry-initializer-rails'
|
50
|
+
|
51
|
+
class CreateOrder
|
52
|
+
extend Dry::Initializer::Mixin
|
53
|
+
extend Dry::Initializer::Rails
|
54
|
+
|
55
|
+
# Params and options
|
56
|
+
param :customer, model: 'Customer' # use either a name
|
57
|
+
option :product, model: Product # or a class
|
58
|
+
|
59
|
+
def call
|
60
|
+
Order.create customer: customer, product: product
|
61
|
+
end
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
Now you can assign values as pre-initialized model instances:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
customer = Customer.find(1)
|
69
|
+
product = Product.find(2)
|
70
|
+
|
71
|
+
order = CreateOrder.new(customer, product: product).call
|
72
|
+
order.customer # => <Customer @id=1 ...>
|
73
|
+
order.product # => <Product @id=2 ...>
|
74
|
+
```
|
75
|
+
|
76
|
+
...or their ids:
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
order = CreateOrder.new(1, product: 2).call
|
80
|
+
order.customer # => <Customer @id=1 ...>
|
81
|
+
order.product # => <Product @id=2 ...>
|
82
|
+
```
|
83
|
+
|
84
|
+
The instance is envoked using method `find_by(id: ...)`.
|
85
|
+
With wrong ids `nil` values are assigned to a corresponding params and options:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
order = CreateOrder.new(0, product: 0).call
|
89
|
+
order.customer # => nil
|
90
|
+
order.product # => nil
|
91
|
+
```
|
92
|
+
|
93
|
+
You can specify custom `key` for searching model instance:
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
require 'dry-initializer-rails'
|
97
|
+
|
98
|
+
class CreateOrder
|
99
|
+
extend Dry::Initializer::Mixin
|
100
|
+
extend Dry::Initializer::Rails
|
101
|
+
|
102
|
+
param :customer, model: 'User', find_by: 'name'
|
103
|
+
option :product, model: Item, find_by: :name
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
This time you can pass names (not ids) to the initializer:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
order = CreateOrder.new('Andrew', product: 'the_thing_no_123').call
|
111
|
+
|
112
|
+
order.customer # => <User @name='Andrew' ...>
|
113
|
+
order.product # => <Item @name='the_thing_no_123' ...>
|
114
|
+
```
|
115
|
+
|
116
|
+
## Compatibility
|
117
|
+
|
118
|
+
Tested under [MRI 2.2+](.travis.yml).
|
119
|
+
|
120
|
+
## Contributing
|
121
|
+
|
122
|
+
* [Fork the project](https://github.com/dry-rb/dry-initializer-rails)
|
123
|
+
* Create your feature branch (`git checkout -b my-new-feature`)
|
124
|
+
* Add tests for it
|
125
|
+
* Commit your changes (`git commit -am '[UPDATE] Add some feature'`)
|
126
|
+
* Push to the branch (`git push origin my-new-feature`)
|
127
|
+
* Create a new Pull Request
|
128
|
+
|
129
|
+
## License
|
130
|
+
|
131
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
132
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
# Adds dummy:db tasks.
|
7
|
+
load "spec/dummy/Rakefile"
|
8
|
+
|
9
|
+
# Declares gem's own tasks.
|
10
|
+
desc "Runs test suite."
|
11
|
+
task default: %w(dummy:db:migrate) do
|
12
|
+
system "bundle exec rspec spec"
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "dry-initializer-rails"
|
3
|
+
gem.version = "0.0.1"
|
4
|
+
gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
|
5
|
+
gem.email = ["hashtable@yandex.ru", "andrew.kozin@gmail.com"]
|
6
|
+
gem.homepage = "https://github.com/nepalez/dry-initializer-rails"
|
7
|
+
gem.summary = "Adds ActiveRecord-specific methods to Dry::Initializer"
|
8
|
+
gem.license = "MIT"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
11
|
+
gem.test_files = gem.files.grep(/^spec/)
|
12
|
+
gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
|
13
|
+
|
14
|
+
gem.required_ruby_version = ">= 2.2"
|
15
|
+
|
16
|
+
gem.add_runtime_dependency "rails", "> 3.0"
|
17
|
+
gem.add_runtime_dependency "dry-initializer", "~> 0.2.0"
|
18
|
+
|
19
|
+
gem.add_development_dependency "rspec", "~> 3.0"
|
20
|
+
gem.add_development_dependency "rake", "> 10.0"
|
21
|
+
gem.add_development_dependency "sqlite3", "~> 1.3"
|
22
|
+
gem.add_development_dependency "database_cleaner", "~> 1.5"
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Dry::Initializer::Rails
|
2
|
+
# The plugin provides chunk of code to find rails model instance by key
|
3
|
+
class Model < Dry::Initializer::Plugins::Base
|
4
|
+
def call
|
5
|
+
return unless settings.key? :model
|
6
|
+
|
7
|
+
"@#{name} = #{model}.find_by(#{model_key}: @#{name})" \
|
8
|
+
" unless @#{name} == #{undefined} || #{model} === @#{name}"
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def model
|
14
|
+
@model ||= settings[:model]
|
15
|
+
end
|
16
|
+
|
17
|
+
def model_key
|
18
|
+
@key ||= settings.fetch(:find_by, :id)
|
19
|
+
end
|
20
|
+
|
21
|
+
def undefined
|
22
|
+
"Dry::Initializer::UNDEFINED"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "dry-initializer"
|
2
|
+
require "rails"
|
3
|
+
|
4
|
+
# Rails plugin to dry-initializer gem
|
5
|
+
module Dry::Initializer::Rails
|
6
|
+
extend Dry::Initializer::Mixin
|
7
|
+
|
8
|
+
require_relative "rails/model"
|
9
|
+
|
10
|
+
def self.extended(klass)
|
11
|
+
klass.initializer_builder.register Model
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "dry/initializer/rails"
|
@@ -0,0 +1,60 @@
|
|
1
|
+
describe "assignment by custom key" do
|
2
|
+
context "with mixin syntax" do
|
3
|
+
before do
|
4
|
+
class Test::Order
|
5
|
+
extend Dry::Initializer::Mixin
|
6
|
+
extend Dry::Initializer::Rails
|
7
|
+
|
8
|
+
param :user, model: "User", find_by: "name"
|
9
|
+
option :product, model: Item, find_by: :name
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let!(:user) { User.create name: "Dude" }
|
14
|
+
let!(:item) { Item.create name: "The thing" }
|
15
|
+
|
16
|
+
it "works when records are present" do
|
17
|
+
subject = Test::Order.new("Dude", product: "The thing")
|
18
|
+
|
19
|
+
expect(subject.user).to eql user
|
20
|
+
expect(subject.product).to eql item
|
21
|
+
end
|
22
|
+
|
23
|
+
it "works when records are absent" do
|
24
|
+
subject = Test::Order.new("Man", product: "Something strange")
|
25
|
+
|
26
|
+
expect(subject.user).to be_nil
|
27
|
+
expect(subject.product).to be_nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with container syntax" do
|
32
|
+
before do
|
33
|
+
class Test::Order
|
34
|
+
include Dry::Initializer.define -> do
|
35
|
+
extend Dry::Initializer::Rails
|
36
|
+
|
37
|
+
param :user, model: "User", find_by: "name"
|
38
|
+
option :product, model: Item, find_by: :name
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
let!(:user) { User.create name: "Dude" }
|
44
|
+
let!(:item) { Item.create name: "The thing" }
|
45
|
+
|
46
|
+
it "works when records are present" do
|
47
|
+
subject = Test::Order.new("Dude", product: "The thing")
|
48
|
+
|
49
|
+
expect(subject.user).to eql user
|
50
|
+
expect(subject.product).to eql item
|
51
|
+
end
|
52
|
+
|
53
|
+
it "works when records are absent" do
|
54
|
+
subject = Test::Order.new("Man", product: "Something strange")
|
55
|
+
|
56
|
+
expect(subject.user).to be_nil
|
57
|
+
expect(subject.product).to be_nil
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
describe "assignment by id" do
|
2
|
+
before do
|
3
|
+
class Test::Order
|
4
|
+
extend Dry::Initializer::Mixin
|
5
|
+
extend Dry::Initializer::Rails
|
6
|
+
|
7
|
+
param :user, model: "User"
|
8
|
+
option :product, model: Item
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let!(:user) { User.create name: "Dude" }
|
13
|
+
let!(:item) { Item.create name: "The thing" }
|
14
|
+
|
15
|
+
it "works when records are present" do
|
16
|
+
subject = Test::Order.new(user.id, product: item.id)
|
17
|
+
|
18
|
+
expect(subject.user).to eql user
|
19
|
+
expect(subject.product).to eql item
|
20
|
+
end
|
21
|
+
|
22
|
+
it "works when records are absent" do
|
23
|
+
subject = Test::Order.new(0, product: 0)
|
24
|
+
|
25
|
+
expect(subject.user).to be_nil
|
26
|
+
expect(subject.product).to be_nil
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
describe "assignment by model" do
|
2
|
+
before do
|
3
|
+
class Test::Order
|
4
|
+
extend Dry::Initializer::Mixin
|
5
|
+
extend Dry::Initializer::Rails
|
6
|
+
|
7
|
+
param :user, model: "User"
|
8
|
+
option :product, model: Item
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
let!(:user) { User.create name: "Dude" }
|
13
|
+
let!(:item) { Item.create name: "The thing" }
|
14
|
+
|
15
|
+
it "works" do
|
16
|
+
subject = Test::Order.new(user, product: item)
|
17
|
+
|
18
|
+
expect(subject.user).to eql user
|
19
|
+
expect(subject.product).to eql item
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe "base syntax" do
|
2
|
+
before do
|
3
|
+
class Test::Foo
|
4
|
+
extend Dry::Initializer::Mixin
|
5
|
+
extend Dry::Initializer::Rails
|
6
|
+
|
7
|
+
param :foo
|
8
|
+
param :bar
|
9
|
+
option :baz
|
10
|
+
option :qux
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "supported" do
|
15
|
+
subject = Test::Foo.new(1, 2, baz: 3, qux: 4)
|
16
|
+
|
17
|
+
expect(subject.foo).to eql 1
|
18
|
+
expect(subject.bar).to eql 2
|
19
|
+
expect(subject.baz).to eql 3
|
20
|
+
expect(subject.qux).to eql 4
|
21
|
+
end
|
22
|
+
end
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
namespace :dummy do
|
5
|
+
task :environment do
|
6
|
+
require_relative "lib/dummy"
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :db do
|
10
|
+
task load_config: :environment
|
11
|
+
end
|
12
|
+
|
13
|
+
load "active_record/railties/databases.rake"
|
14
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Dummy::Application.configure do |config|
|
2
|
+
dummy = File.expand_path "../..", __FILE__
|
3
|
+
database_yml = File.join(dummy, "config/database.yml")
|
4
|
+
|
5
|
+
config.database_configuration = YAML.load File.read(database_yml)
|
6
|
+
config.db_dir = File.join(dummy, "db")
|
7
|
+
config.env = :test
|
8
|
+
config.migrations_paths = [File.join(dummy, "db/migrate")]
|
9
|
+
config.root = dummy
|
10
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20160509134900) do
|
15
|
+
|
16
|
+
create_table "items", force: :cascade do |t|
|
17
|
+
t.string "name"
|
18
|
+
end
|
19
|
+
|
20
|
+
add_index "items", ["name"], name: "index_items_on_name"
|
21
|
+
|
22
|
+
create_table "users", force: :cascade do |t|
|
23
|
+
t.string "name"
|
24
|
+
end
|
25
|
+
|
26
|
+
add_index "users", ["name"], name: "index_users_on_name"
|
27
|
+
|
28
|
+
end
|
Binary file
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Dummy
|
2
|
+
class Application
|
3
|
+
class << self
|
4
|
+
# Configuration settings wrapper for the
|
5
|
+
# <tt>ActiveRecord::Tasks::DatabaseTasks</tt>.
|
6
|
+
#
|
7
|
+
# Establishes AR connection after configuration.
|
8
|
+
#
|
9
|
+
def configure
|
10
|
+
yield tasks
|
11
|
+
base.configurations = tasks.database_configuration
|
12
|
+
base.establish_connection(tasks.env)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def base
|
18
|
+
@base ||= ActiveRecord::Base
|
19
|
+
end
|
20
|
+
|
21
|
+
def tasks
|
22
|
+
@tasks ||= ActiveRecord::Tasks::DatabaseTasks
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "dry/initializer/rails"
|
2
|
+
require "pry"
|
3
|
+
require "database_cleaner"
|
4
|
+
|
5
|
+
require_relative "dummy/lib/dummy"
|
6
|
+
|
7
|
+
DatabaseCleaner.strategy = :truncation
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.order = :random
|
11
|
+
config.filter_run focus: true
|
12
|
+
config.run_all_when_everything_filtered = true
|
13
|
+
|
14
|
+
# Prepare the Test namespace for constants defined in specs
|
15
|
+
config.around(:each) do |example|
|
16
|
+
Test = Class.new(Module)
|
17
|
+
example.run
|
18
|
+
Object.send :remove_const, :Test
|
19
|
+
DatabaseCleaner.clean
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dry-initializer-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladimir Kochnev (marshall-lee)
|
8
|
+
- Andrew Kozin (nepalez)
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: dry-initializer
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.2.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.2.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '10.0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '10.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: sqlite3
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '1.3'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.3'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: database_cleaner
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '1.5'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '1.5'
|
98
|
+
description:
|
99
|
+
email:
|
100
|
+
- hashtable@yandex.ru
|
101
|
+
- andrew.kozin@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files:
|
105
|
+
- README.md
|
106
|
+
- CHANGELOG.md
|
107
|
+
files:
|
108
|
+
- ".codeclimate.yml"
|
109
|
+
- ".gitignore"
|
110
|
+
- ".rspec"
|
111
|
+
- ".rubocop.yml"
|
112
|
+
- ".travis.yml"
|
113
|
+
- CHANGELOG.md
|
114
|
+
- Gemfile
|
115
|
+
- Guardfile
|
116
|
+
- LICENSE.txt
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- dry-initializer-rails.gemspec
|
120
|
+
- lib/dry-initializer-rails.rb
|
121
|
+
- lib/dry/initializer/rails.rb
|
122
|
+
- lib/dry/initializer/rails/model.rb
|
123
|
+
- spec/dry/initializer/assignment_by_custom_key_spec.rb
|
124
|
+
- spec/dry/initializer/assignment_by_id_spec.rb
|
125
|
+
- spec/dry/initializer/assignment_by_model_spec.rb
|
126
|
+
- spec/dry/initializer/base_syntax_spec.rb
|
127
|
+
- spec/dummy/Rakefile
|
128
|
+
- spec/dummy/app/models/item.rb
|
129
|
+
- spec/dummy/app/models/user.rb
|
130
|
+
- spec/dummy/config/database.yml
|
131
|
+
- spec/dummy/config/environment.rb
|
132
|
+
- spec/dummy/db/migrate/20160509134800_create_users.rb
|
133
|
+
- spec/dummy/db/migrate/20160509134900_create_items.rb
|
134
|
+
- spec/dummy/db/schema.rb
|
135
|
+
- spec/dummy/db/test.sqlite3
|
136
|
+
- spec/dummy/lib/dummy.rb
|
137
|
+
- spec/dummy/lib/dummy/application.rb
|
138
|
+
- spec/spec_helper.rb
|
139
|
+
homepage: https://github.com/nepalez/dry-initializer-rails
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '2.2'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.6.4
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Adds ActiveRecord-specific methods to Dry::Initializer
|
163
|
+
test_files:
|
164
|
+
- spec/dry/initializer/assignment_by_custom_key_spec.rb
|
165
|
+
- spec/dry/initializer/assignment_by_id_spec.rb
|
166
|
+
- spec/dry/initializer/assignment_by_model_spec.rb
|
167
|
+
- spec/dry/initializer/base_syntax_spec.rb
|
168
|
+
- spec/dummy/Rakefile
|
169
|
+
- spec/dummy/app/models/item.rb
|
170
|
+
- spec/dummy/app/models/user.rb
|
171
|
+
- spec/dummy/config/database.yml
|
172
|
+
- spec/dummy/config/environment.rb
|
173
|
+
- spec/dummy/db/migrate/20160509134800_create_users.rb
|
174
|
+
- spec/dummy/db/migrate/20160509134900_create_items.rb
|
175
|
+
- spec/dummy/db/schema.rb
|
176
|
+
- spec/dummy/db/test.sqlite3
|
177
|
+
- spec/dummy/lib/dummy.rb
|
178
|
+
- spec/dummy/lib/dummy/application.rb
|
179
|
+
- spec/spec_helper.rb
|
180
|
+
has_rdoc:
|