dry-initializer-rails 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +14 -55
- data/.travis.yml +9 -5
- data/CHANGELOG.md +6 -4
- data/README.md +2 -4
- data/dry-initializer-rails.gemspec +5 -4
- data/lib/dry/initializer/rails.rb +12 -7
- data/spec/dry/initializer/assignment_by_custom_key_spec.rb +1 -4
- data/spec/dry/initializer/assignment_by_id_spec.rb +1 -2
- data/spec/dry/initializer/assignment_by_model_spec.rb +1 -2
- data/spec/dry/initializer/base_syntax_spec.rb +1 -2
- data/spec/dummy/db/schema.rb +2 -5
- data/spec/spec_helper.rb +1 -1
- metadata +22 -16
- data/lib/dry/initializer/rails/model.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ccebd9d7adeb8e25c29b0327989ffaf58117c43
|
4
|
+
data.tar.gz: ffc23d3c5a6a1b12dd67ffdab61454d8305b1a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6075002cc04d3bbb779a7002ab91d8cc9ee364a757cf9d335c7ce14e4641e549326144e68135384fdf0da87c1ad1357c0e1f13734e4d9b834c24940bc49fb240
|
7
|
+
data.tar.gz: 4f73db23fc8ebca08db64e51dba85a1b3de11a10ebb7e0fd2f779b60c4c2f5d8e5a55aa223632d477ef067c077f3b1e16d0398112186eaf9110f1f4e3c14f604
|
data/.rubocop.yml
CHANGED
@@ -5,87 +5,46 @@ AllCops:
|
|
5
5
|
StyleGuideCopsOnly: true
|
6
6
|
TargetRubyVersion: 2.2
|
7
7
|
|
8
|
-
Lint/HandleExceptions:
|
9
|
-
Exclude:
|
10
|
-
- '**/*_spec.rb'
|
11
|
-
|
12
|
-
Lint/RescueException:
|
13
|
-
Exclude:
|
14
|
-
- '**/*_spec.rb'
|
15
|
-
|
16
8
|
Metrics/LineLength:
|
17
|
-
Max: 80
|
18
9
|
Exclude:
|
19
|
-
-
|
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
|
10
|
+
- spec/dummy/db/schema.rb
|
30
11
|
|
31
12
|
Style/CaseEquality:
|
32
13
|
Enabled: false
|
33
14
|
|
34
|
-
Style/
|
35
|
-
Enabled: false
|
36
|
-
|
37
|
-
Style/Documentation:
|
15
|
+
Style/ClassVars:
|
38
16
|
Enabled: false
|
39
17
|
|
40
18
|
Style/DoubleNegation:
|
41
19
|
Enabled: false
|
42
20
|
|
43
|
-
Style/EmptyLinesAroundClassBody:
|
44
|
-
Enabled: false
|
45
|
-
|
46
|
-
Style/EmptyLinesAroundModuleBody:
|
47
|
-
Enabled: false
|
48
|
-
|
49
|
-
Style/EmptyLineBetweenDefs:
|
50
|
-
Enabled: false
|
51
|
-
|
52
21
|
Style/FileName:
|
53
|
-
|
22
|
+
Exclude:
|
23
|
+
- 'lib/dry-initializer-rails.rb'
|
24
|
+
|
25
|
+
Style/Lambda:
|
26
|
+
Exclude:
|
27
|
+
- spec/**/*_spec.rb
|
54
28
|
|
55
|
-
Style/
|
29
|
+
Style/LambdaCall:
|
56
30
|
Enabled: false
|
57
31
|
|
32
|
+
Style/NumericLiterals:
|
33
|
+
Exclude:
|
34
|
+
- spec/dummy/db/schema.rb
|
35
|
+
|
58
36
|
Style/RaiseArgs:
|
59
37
|
EnforcedStyle: compact
|
60
38
|
|
61
39
|
Style/Semicolon:
|
62
40
|
Exclude:
|
63
|
-
-
|
41
|
+
- spec/**/*_spec.rb
|
64
42
|
|
65
43
|
Style/SignalException:
|
66
44
|
EnforcedStyle: semantic
|
67
45
|
|
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
46
|
Style/StringLiterals:
|
84
47
|
EnforcedStyle: double_quotes
|
85
48
|
|
86
49
|
Style/StringLiteralsInInterpolation:
|
87
50
|
EnforcedStyle: double_quotes
|
88
|
-
|
89
|
-
Style/TrivialAccessors:
|
90
|
-
Exclude:
|
91
|
-
- '**/*_spec.rb'
|
data/.travis.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
---
|
2
2
|
language: ruby
|
3
|
-
|
4
|
-
cache:
|
5
|
-
|
3
|
+
sudo: false
|
4
|
+
cache: bundler
|
5
|
+
before_install: gem install bundler --no-ri --no-rdoc
|
6
|
+
bundler_args: --without benchmarks tools
|
7
|
+
script:
|
8
|
+
- bundle exec rake
|
9
|
+
- bundle exec rubocop
|
6
10
|
rvm:
|
7
|
-
-
|
8
|
-
-
|
11
|
+
- 2.2.2
|
12
|
+
- 2.3.0
|
9
13
|
- ruby-head
|
10
14
|
matrix:
|
11
15
|
allow_failures:
|
data/CHANGELOG.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
## v1.0.0 2017-01-28
|
2
|
+
|
3
|
+
Update dependency to dry-initializer v1.1+ (nepalez)
|
4
|
+
|
1
5
|
## v0.0.3 2016-07-17
|
2
6
|
|
3
|
-
Support dry-initializer v0.4+ (
|
7
|
+
Support dry-initializer v0.4+ (nepalez)
|
4
8
|
|
5
9
|
## v0.0.2 2016-05-19
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
[Compare v0.0.1...v0.0.2](https://github.com/dry-rb/dry-initializer/compare/v0.0.1..v0.0.2)
|
11
|
+
Update dependency to dry-initializer v0.3+ (nepalez)
|
10
12
|
|
11
13
|
## v0.0.1 2016-05-16
|
12
14
|
|
data/README.md
CHANGED
@@ -49,8 +49,7 @@ require 'dry-initializer'
|
|
49
49
|
require 'dry-initializer-rails'
|
50
50
|
|
51
51
|
class CreateOrder
|
52
|
-
extend Dry::Initializer
|
53
|
-
extend Dry::Initializer::Rails
|
52
|
+
extend Dry::Initializer
|
54
53
|
|
55
54
|
# Params and options
|
56
55
|
param :customer, model: 'Customer' # use either a name
|
@@ -96,8 +95,7 @@ You can specify custom `key` for searching model instance:
|
|
96
95
|
require 'dry-initializer-rails'
|
97
96
|
|
98
97
|
class CreateOrder
|
99
|
-
extend Dry::Initializer
|
100
|
-
extend Dry::Initializer::Rails
|
98
|
+
extend Dry::Initializer
|
101
99
|
|
102
100
|
param :customer, model: 'User', find_by: 'name'
|
103
101
|
option :product, model: Item, find_by: :name
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "dry-initializer-rails"
|
3
|
-
gem.version = "0.0
|
3
|
+
gem.version = "1.0.0"
|
4
4
|
gem.author = ["Vladimir Kochnev (marshall-lee)", "Andrew Kozin (nepalez)"]
|
5
5
|
gem.email = ["hashtable@yandex.ru", "andrew.kozin@gmail.com"]
|
6
6
|
gem.homepage = "https://github.com/nepalez/dry-initializer-rails"
|
@@ -11,13 +11,14 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.test_files = gem.files.grep(/^spec/)
|
12
12
|
gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
|
13
13
|
|
14
|
-
gem.required_ruby_version = ">= 2.2"
|
14
|
+
gem.required_ruby_version = ">= 2.2.2"
|
15
15
|
|
16
|
-
gem.add_runtime_dependency "rails", "> 3.0"
|
17
|
-
gem.add_runtime_dependency "dry-initializer", "
|
16
|
+
gem.add_runtime_dependency "rails", "> 3.0"
|
17
|
+
gem.add_runtime_dependency "dry-initializer", "~> 1.1"
|
18
18
|
|
19
19
|
gem.add_development_dependency "rspec", "~> 3.0"
|
20
20
|
gem.add_development_dependency "rake", "> 10.0"
|
21
21
|
gem.add_development_dependency "sqlite3", "~> 1.3"
|
22
22
|
gem.add_development_dependency "database_cleaner", "~> 1.5"
|
23
|
+
gem.add_development_dependency "rubocop", "~> 0.44"
|
23
24
|
end
|
@@ -1,13 +1,18 @@
|
|
1
1
|
require "dry-initializer"
|
2
2
|
require "rails"
|
3
3
|
|
4
|
-
#
|
5
|
-
|
6
|
-
|
4
|
+
# Define a dispatcher for `:model` and `:find_by` options
|
5
|
+
rails_dispatcher = lambda do |model: nil, find_by: :id, **options|
|
6
|
+
return options unless model
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
model = model.constantize if model.is_a? String
|
9
|
+
coercer = lambda do |value|
|
10
|
+
return value if value.instance_of? model
|
11
|
+
model.find_by(find_by => value)
|
12
12
|
end
|
13
|
+
|
14
|
+
options.merge(type: coercer)
|
13
15
|
end
|
16
|
+
|
17
|
+
# Register a dispatcher
|
18
|
+
Dry::Initializer::Attribute.dispatchers << rails_dispatcher
|
@@ -2,8 +2,7 @@ describe "assignment by custom key" do
|
|
2
2
|
context "with mixin syntax" do
|
3
3
|
before do
|
4
4
|
class Test::Order
|
5
|
-
extend Dry::Initializer
|
6
|
-
extend Dry::Initializer::Rails
|
5
|
+
extend Dry::Initializer
|
7
6
|
|
8
7
|
param :user, model: "User", find_by: "name"
|
9
8
|
option :product, model: Item, find_by: :name
|
@@ -32,8 +31,6 @@ describe "assignment by custom key" do
|
|
32
31
|
before do
|
33
32
|
class Test::Order
|
34
33
|
include Dry::Initializer.define -> do
|
35
|
-
extend Dry::Initializer::Rails
|
36
|
-
|
37
34
|
param :user, model: "User", find_by: "name"
|
38
35
|
option :product, model: Item, find_by: :name
|
39
36
|
end
|
data/spec/dummy/db/schema.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: UTF-8
|
2
1
|
# This file is auto-generated from the current state of the database. Instead
|
3
2
|
# of editing this file, please use the migrations feature of Active Record to
|
4
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
@@ -15,14 +14,12 @@ ActiveRecord::Schema.define(version: 20160509134900) do
|
|
15
14
|
|
16
15
|
create_table "items", force: :cascade do |t|
|
17
16
|
t.string "name"
|
17
|
+
t.index ["name"], name: "index_items_on_name"
|
18
18
|
end
|
19
19
|
|
20
|
-
add_index "items", ["name"], name: "index_items_on_name"
|
21
|
-
|
22
20
|
create_table "users", force: :cascade do |t|
|
23
21
|
t.string "name"
|
22
|
+
t.index ["name"], name: "index_users_on_name"
|
24
23
|
end
|
25
24
|
|
26
|
-
add_index "users", ["name"], name: "index_users_on_name"
|
27
|
-
|
28
25
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-initializer-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kochnev (marshall-lee)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -18,9 +18,6 @@ dependencies:
|
|
18
18
|
- - ">"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '3.0'
|
21
|
-
- - "<"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: '5.0'
|
24
21
|
type: :runtime
|
25
22
|
prerelease: false
|
26
23
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -28,23 +25,20 @@ dependencies:
|
|
28
25
|
- - ">"
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '3.0'
|
31
|
-
- - "<"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5.0'
|
34
28
|
- !ruby/object:Gem::Dependency
|
35
29
|
name: dry-initializer
|
36
30
|
requirement: !ruby/object:Gem::Requirement
|
37
31
|
requirements:
|
38
|
-
- - "
|
32
|
+
- - "~>"
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
34
|
+
version: '1.1'
|
41
35
|
type: :runtime
|
42
36
|
prerelease: false
|
43
37
|
version_requirements: !ruby/object:Gem::Requirement
|
44
38
|
requirements:
|
45
|
-
- - "
|
39
|
+
- - "~>"
|
46
40
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
41
|
+
version: '1.1'
|
48
42
|
- !ruby/object:Gem::Dependency
|
49
43
|
name: rspec
|
50
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,6 +95,20 @@ dependencies:
|
|
101
95
|
- - "~>"
|
102
96
|
- !ruby/object:Gem::Version
|
103
97
|
version: '1.5'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0.44'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0.44'
|
104
112
|
description:
|
105
113
|
email:
|
106
114
|
- hashtable@yandex.ru
|
@@ -125,7 +133,6 @@ files:
|
|
125
133
|
- dry-initializer-rails.gemspec
|
126
134
|
- lib/dry-initializer-rails.rb
|
127
135
|
- lib/dry/initializer/rails.rb
|
128
|
-
- lib/dry/initializer/rails/model.rb
|
129
136
|
- spec/dry/initializer/assignment_by_custom_key_spec.rb
|
130
137
|
- spec/dry/initializer/assignment_by_id_spec.rb
|
131
138
|
- spec/dry/initializer/assignment_by_model_spec.rb
|
@@ -153,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
160
|
requirements:
|
154
161
|
- - ">="
|
155
162
|
- !ruby/object:Gem::Version
|
156
|
-
version:
|
163
|
+
version: 2.2.2
|
157
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
165
|
requirements:
|
159
166
|
- - ">="
|
@@ -161,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
168
|
version: '0'
|
162
169
|
requirements: []
|
163
170
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
171
|
+
rubygems_version: 2.5.2
|
165
172
|
signing_key:
|
166
173
|
specification_version: 4
|
167
174
|
summary: Adds ActiveRecord-specific methods to Dry::Initializer
|
@@ -181,4 +188,3 @@ test_files:
|
|
181
188
|
- spec/dummy/lib/dummy.rb
|
182
189
|
- spec/dummy/lib/dummy/application.rb
|
183
190
|
- spec/spec_helper.rb
|
184
|
-
has_rdoc:
|
@@ -1,25 +0,0 @@
|
|
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
|