mv-core 2.2.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mv/core/constraint/base.rb +3 -3
- data/lib/mv/core/constraint/builder/factory.rb +5 -5
- data/lib/mv/core/constraint/builder/index.rb +7 -7
- data/lib/mv/core/constraint/builder/trigger.rb +2 -2
- data/lib/mv/core/constraint/factory.rb +5 -5
- data/lib/mv/core/constraint/index.rb +2 -5
- data/lib/mv/core/constraint/trigger.rb +4 -4
- data/lib/mv/core/db/helpers/column_validators.rb +7 -7
- data/lib/mv/core/db/helpers/table_validators.rb +4 -4
- data/lib/mv/core/migration/operations/factory.rb +7 -7
- data/lib/mv/core/services/create_migration_validators_table.rb +6 -6
- data/lib/mv/core/services/uninstall.rb +4 -4
- data/lib/mv/core/validation/absence.rb +2 -2
- data/lib/mv/core/validation/active_model_presenter/absence.rb +2 -2
- data/lib/mv/core/validation/active_model_presenter/exclusion.rb +2 -2
- data/lib/mv/core/validation/active_model_presenter/factory.rb +7 -7
- data/lib/mv/core/validation/active_model_presenter/inclusion.rb +2 -2
- data/lib/mv/core/validation/active_model_presenter/length.rb +2 -2
- data/lib/mv/core/validation/active_model_presenter/presence.rb +2 -2
- data/lib/mv/core/validation/active_model_presenter/uniqueness.rb +2 -2
- data/lib/mv/core/validation/base_collection.rb +38 -0
- data/lib/mv/core/validation/builder/absence.rb +2 -2
- data/lib/mv/core/validation/builder/custom.rb +4 -4
- data/lib/mv/core/validation/builder/exclusion.rb +8 -8
- data/lib/mv/core/validation/builder/factory.rb +8 -8
- data/lib/mv/core/validation/builder/inclusion.rb +9 -9
- data/lib/mv/core/validation/builder/length.rb +8 -8
- data/lib/mv/core/validation/builder/presence.rb +2 -2
- data/lib/mv/core/validation/builder/uniqueness.rb +4 -4
- data/lib/mv/core/validation/custom.rb +4 -4
- data/lib/mv/core/validation/exclusion.rb +3 -23
- data/lib/mv/core/validation/factory.rb +20 -20
- data/lib/mv/core/validation/inclusion.rb +3 -23
- data/lib/mv/core/validation/length.rb +8 -8
- data/lib/mv/core/validation/presence.rb +2 -2
- data/lib/mv/core/validation/uniqueness.rb +4 -4
- metadata +33 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43d849d82d3b77d137a4c1b0dfb2e58918da9696
|
4
|
+
data.tar.gz: 83e484aa9a40f6946f5b8ef77d52f642c375a548
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fafd65fbeeac4a274152bc694faf1f81925fccdf5b35244d0d9350016c38bd37b228176a23c28a874800ec61fbd5243865e04e3e61681ba27a1e0d276dad8b3b
|
7
|
+
data.tar.gz: 4d7bd7089b3b0d448f3b7dbcff1daf917063d2b28c2cce94c96654f8d12b4d3b2fe46dacfb83506df57c53bf77f60edc25b6a1aa3b8d9f62d575e0ac6291bd2c
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'description'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -18,7 +18,7 @@ module Mv
|
|
18
18
|
def <=> other_constraint
|
19
19
|
[self.class.name, description, validations.sort] <=> [other_constraint.class.name, other_constraint.description, other_constraint.validations.sort]
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
def create
|
23
23
|
end
|
24
24
|
|
@@ -30,4 +30,4 @@ module Mv
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'index'
|
2
|
+
require_relative 'trigger'
|
3
3
|
|
4
4
|
module Mv
|
5
5
|
module Core
|
@@ -17,7 +17,7 @@ module Mv
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def register_builders opts
|
20
|
-
opts.each do |constraint_class, builder_class|
|
20
|
+
opts.each do |constraint_class, builder_class|
|
21
21
|
register_builder(constraint_class, builder_class)
|
22
22
|
end
|
23
23
|
end
|
@@ -31,7 +31,7 @@ module Mv
|
|
31
31
|
|
32
32
|
def factory_map
|
33
33
|
@factory_map ||= {
|
34
|
-
Mv::Core::Constraint::Index => Mv::Core::Constraint::Builder::Index,
|
34
|
+
Mv::Core::Constraint::Index => Mv::Core::Constraint::Builder::Index,
|
35
35
|
Mv::Core::Constraint::Trigger => Mv::Core::Constraint::Builder::Trigger
|
36
36
|
}
|
37
37
|
end
|
@@ -39,4 +39,4 @@ module Mv
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -15,7 +15,7 @@ module Mv
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def delete
|
18
|
-
super
|
18
|
+
super
|
19
19
|
|
20
20
|
constraint.validations.group_by(&:table_name).each do |table_name, validations|
|
21
21
|
remove_index(table_name)
|
@@ -23,7 +23,7 @@ module Mv
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def update new_constraint_builder
|
26
|
-
super
|
26
|
+
super
|
27
27
|
|
28
28
|
delete
|
29
29
|
new_constraint_builder.create
|
@@ -32,12 +32,12 @@ module Mv
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def index_exists?(table_name)
|
35
|
-
db.
|
36
|
-
db.index_name_exists?(table_name, name, false)
|
35
|
+
db.data_source_exists?(table_name) &&
|
36
|
+
db.index_name_exists?(table_name, name, false)
|
37
37
|
end
|
38
38
|
|
39
39
|
def remove_index(table_name)
|
40
|
-
db.remove_index
|
40
|
+
db.remove_index(table_name, name: name) if index_exists?(table_name)
|
41
41
|
end
|
42
42
|
|
43
43
|
def add_index(table_name, columns)
|
@@ -47,4 +47,4 @@ module Mv
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
end
|
50
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require_relative 'trigger'
|
2
|
+
require_relative 'index'
|
3
3
|
|
4
4
|
module Mv
|
5
5
|
module Core
|
@@ -19,15 +19,15 @@ module Mv
|
|
19
19
|
delegate :create_constraint, :register_constraint, to: :instance
|
20
20
|
end
|
21
21
|
|
22
|
-
private
|
22
|
+
private
|
23
23
|
|
24
24
|
def factory_map
|
25
25
|
@factory_map ||= {
|
26
|
-
trigger: Mv::Core::Constraint::Trigger,
|
26
|
+
trigger: Mv::Core::Constraint::Trigger,
|
27
27
|
index: Mv::Core::Constraint::Index
|
28
28
|
}
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
5
5
|
module Constraint
|
6
6
|
class Trigger < Base
|
7
7
|
attr_reader :event
|
8
|
-
|
8
|
+
|
9
9
|
def initialize description
|
10
|
-
super
|
10
|
+
super
|
11
11
|
@event = @description.options[:event].try(:to_sym)
|
12
12
|
end
|
13
13
|
|
@@ -17,4 +17,4 @@ module Mv
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'mv/core/validation/factory'
|
2
|
-
|
2
|
+
require_relative 'table_validators'
|
3
3
|
|
4
4
|
module Mv
|
5
5
|
module Core
|
@@ -20,10 +20,10 @@ module Mv
|
|
20
20
|
update_column_validator(validation_type, opts)
|
21
21
|
end
|
22
22
|
|
23
|
-
def delete_column_validator
|
23
|
+
def delete_column_validator
|
24
24
|
delete_validators(column_validators) > 0
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def update_column_validator validation_type, opts
|
28
28
|
return delete_validators(column_validators.where(validation_type: validation_type)) if opts == false
|
29
29
|
|
@@ -44,9 +44,9 @@ module Mv
|
|
44
44
|
|
45
45
|
def raise_column_validation_error validation_type, opts
|
46
46
|
raise Mv::Core::Error.new(
|
47
|
-
table_name: table_name,
|
48
|
-
column_name: column_name,
|
49
|
-
validation_type: validation_type,
|
47
|
+
table_name: table_name,
|
48
|
+
column_name: column_name,
|
49
|
+
validation_type: validation_type,
|
50
50
|
options: opts,
|
51
51
|
error: 'Validator can not be removed when new column is being added'
|
52
52
|
)
|
@@ -55,4 +55,4 @@ module Mv
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
|
-
end
|
58
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative '../migration_validator'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -6,7 +6,7 @@ module Mv
|
|
6
6
|
module Helpers
|
7
7
|
module TableValidators
|
8
8
|
attr_accessor :table_name
|
9
|
-
|
9
|
+
|
10
10
|
def table_validators
|
11
11
|
Mv::Core::Db::MigrationValidator.where(table_name: table_name)
|
12
12
|
end
|
@@ -21,7 +21,7 @@ module Mv
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
def say(message)
|
24
|
+
def say(message)
|
25
25
|
::ActiveRecord::Migration.say(message, true)
|
26
26
|
end
|
27
27
|
|
@@ -35,4 +35,4 @@ module Mv
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
-
end
|
38
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require_relative 'add_column'
|
2
|
+
require_relative 'change_column'
|
3
|
+
require_relative 'drop_table'
|
4
|
+
require_relative 'remove_column'
|
5
|
+
require_relative 'rename_column'
|
6
|
+
require_relative 'rename_table'
|
7
7
|
|
8
8
|
module Mv
|
9
9
|
module Core
|
@@ -17,4 +17,4 @@ module Mv
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
@@ -3,24 +3,24 @@ module Mv
|
|
3
3
|
module Services
|
4
4
|
class CreateMigrationValidatorsTable
|
5
5
|
attr_reader :db
|
6
|
-
delegate :create_table, :
|
6
|
+
delegate :create_table, :data_source_exists?, :add_index, to: :db
|
7
7
|
|
8
8
|
def initialize db = ::ActiveRecord::Base.connection
|
9
9
|
@db = db
|
10
10
|
end
|
11
11
|
|
12
12
|
def execute
|
13
|
-
unless
|
13
|
+
unless data_source_exists?(:migration_validators)
|
14
14
|
::ActiveRecord::Migration.say_with_time('initialize migration_validators table') do
|
15
15
|
create_table(:migration_validators) do |table|
|
16
16
|
table.string :table_name, null: false
|
17
17
|
table.string :column_name, null: false
|
18
18
|
table.string :validation_type, null: false
|
19
19
|
table.string :options
|
20
|
-
end
|
20
|
+
end
|
21
21
|
|
22
|
-
add_index(:migration_validators,
|
23
|
-
[:table_name, :column_name, :validation_type],
|
22
|
+
add_index(:migration_validators,
|
23
|
+
[:table_name, :column_name, :validation_type],
|
24
24
|
name: 'unique_idx_on_migration_validators')
|
25
25
|
end
|
26
26
|
end
|
@@ -28,4 +28,4 @@ module Mv
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -5,11 +5,11 @@ module Mv
|
|
5
5
|
module Services
|
6
6
|
class Uninstall
|
7
7
|
def execute
|
8
|
-
if db.
|
8
|
+
if db.data_source_exists?(:migration_validators)
|
9
9
|
Mv::Core::Services::DeleteConstraints.new.execute
|
10
|
-
|
10
|
+
|
11
11
|
::ActiveRecord::Migration.say_with_time('drop migration_validators table') do
|
12
|
-
db.drop_table(:migration_validators)
|
12
|
+
db.drop_table(:migration_validators)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -22,4 +22,4 @@ module Mv
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
require_relative 'exclusion'
|
2
|
+
require_relative 'inclusion'
|
3
|
+
require_relative 'length'
|
4
|
+
require_relative 'presence'
|
5
|
+
require_relative 'absence'
|
6
|
+
require_relative 'uniqueness'
|
7
7
|
|
8
8
|
module Mv
|
9
9
|
module Core
|
@@ -48,4 +48,4 @@ module Mv
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'mv/core/validators/array_validator'
|
2
|
+
require_relative 'base'
|
3
|
+
|
4
|
+
module Mv
|
5
|
+
module Core
|
6
|
+
module Validation
|
7
|
+
class BaseCollection < Base
|
8
|
+
include ActiveModel::Validations
|
9
|
+
|
10
|
+
attr_reader :in
|
11
|
+
|
12
|
+
validates :in, presence: true, array: true
|
13
|
+
|
14
|
+
def initialize(table_name, column_name, opts)
|
15
|
+
opts = opts.is_a?(Hash) ? opts : { in: opts }
|
16
|
+
|
17
|
+
super(table_name, column_name, opts)
|
18
|
+
|
19
|
+
@in = opts.with_indifferent_access[:in]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_a
|
23
|
+
prepared_in = self.in.is_a?(Range) ? range_to_a : self.in.try(:sort)
|
24
|
+
super + [prepared_in]
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def range_to_a
|
30
|
+
min = self.in.min
|
31
|
+
max = self.in.exclude_end? ? self.in.last - 0.000000001.second : self.in.last
|
32
|
+
|
33
|
+
[min, max]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
5
|
-
module Validation
|
5
|
+
module Validation
|
6
6
|
module Builder
|
7
7
|
class Custom < Base
|
8
8
|
delegate :statement, to: :validation
|
9
9
|
|
10
10
|
def conditions
|
11
11
|
[{
|
12
|
-
statement: apply_allow_nil_and_blank("(#{preprocess_statement})"),
|
12
|
+
statement: apply_allow_nil_and_blank("(#{preprocess_statement})"),
|
13
13
|
message: message
|
14
14
|
}]
|
15
15
|
end
|
@@ -23,4 +23,4 @@ module Mv
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -9,7 +9,7 @@ module Mv
|
|
9
9
|
|
10
10
|
def conditions
|
11
11
|
[{
|
12
|
-
statement: apply_allow_nil_and_blank(apply_in(column_reference)),
|
12
|
+
statement: apply_allow_nil_and_blank(apply_in(column_reference)),
|
13
13
|
message: message
|
14
14
|
}]
|
15
15
|
end
|
@@ -19,10 +19,10 @@ module Mv
|
|
19
19
|
def db_value value
|
20
20
|
return value if value.is_a?(Integer) or value.is_a?(Float)
|
21
21
|
return "'#{value.to_s}'" if value.is_a?(String)
|
22
|
-
raise Mv::Core::Error.new(table_name: table_name,
|
23
|
-
column_name: column_name,
|
24
|
-
validation_type: :inclusion,
|
25
|
-
options: { in: value },
|
22
|
+
raise Mv::Core::Error.new(table_name: table_name,
|
23
|
+
column_name: column_name,
|
24
|
+
validation_type: :inclusion,
|
25
|
+
options: { in: value },
|
26
26
|
error: "#{value.class} is not supported as :in value")
|
27
27
|
end
|
28
28
|
|
@@ -32,11 +32,11 @@ module Mv
|
|
32
32
|
else
|
33
33
|
prepared_in = self.in.to_a.collect{ |v| db_value(v) }
|
34
34
|
|
35
|
-
"#{stmt} NOT IN (#{prepared_in.join(', ')})"
|
35
|
+
"#{stmt} NOT IN (#{prepared_in.join(', ')})"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
require_relative 'exclusion'
|
2
|
+
require_relative 'inclusion'
|
3
|
+
require_relative 'length'
|
4
|
+
require_relative 'presence'
|
5
|
+
require_relative 'absence'
|
6
|
+
require_relative 'uniqueness'
|
7
|
+
require_relative 'custom'
|
8
8
|
|
9
9
|
module Mv
|
10
10
|
module Core
|
@@ -42,4 +42,4 @@ module Mv
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
end
|
45
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -9,7 +9,7 @@ module Mv
|
|
9
9
|
|
10
10
|
def conditions
|
11
11
|
[{
|
12
|
-
statement: apply_allow_nil_and_blank(apply_in(column_reference)),
|
12
|
+
statement: apply_allow_nil_and_blank(apply_in(column_reference)),
|
13
13
|
message: message
|
14
14
|
}]
|
15
15
|
end
|
@@ -19,10 +19,10 @@ module Mv
|
|
19
19
|
def db_value value
|
20
20
|
return value if value.is_a?(Integer) or value.is_a?(Float)
|
21
21
|
return "'#{value.to_s}'" if value.is_a?(String)
|
22
|
-
raise Mv::Core::Error.new(table_name: table_name,
|
23
|
-
column_name: column_name,
|
24
|
-
validation_type: :inclusion,
|
25
|
-
options: { in: value },
|
22
|
+
raise Mv::Core::Error.new(table_name: table_name,
|
23
|
+
column_name: column_name,
|
24
|
+
validation_type: :inclusion,
|
25
|
+
options: { in: value },
|
26
26
|
error: "#{value.class} is not supported as :in value")
|
27
27
|
end
|
28
28
|
|
@@ -32,11 +32,11 @@ module Mv
|
|
32
32
|
else
|
33
33
|
prepared_in = self.in.to_a.collect{ |v| db_value(v) }
|
34
34
|
|
35
|
-
"#{stmt} IN (#{prepared_in.join(', ')})"
|
35
|
+
"#{stmt} IN (#{prepared_in.join(', ')})"
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
end
|
40
|
+
end
|
41
41
|
end
|
42
|
-
end
|
42
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
5
5
|
module Validation
|
6
6
|
module Builder
|
7
7
|
class Length < Base
|
8
|
-
delegate :in,
|
9
|
-
:within,
|
10
|
-
:is,
|
11
|
-
:maximum,
|
8
|
+
delegate :in,
|
9
|
+
:within,
|
10
|
+
:is,
|
11
|
+
:maximum,
|
12
12
|
:minimum,
|
13
13
|
to: :validation
|
14
14
|
|
@@ -20,7 +20,7 @@ module Mv
|
|
20
20
|
res = apply_minimum(column_reference) if minimum && !maximum
|
21
21
|
res = apply_minimum_and_maximum(column_reference) if minimum && maximum
|
22
22
|
|
23
|
-
res.collect do |condition|
|
23
|
+
res.collect do |condition|
|
24
24
|
{ statement: apply_allow_nil_and_blank(condition[:statement]), message: condition[:message] }
|
25
25
|
end
|
26
26
|
end
|
@@ -61,7 +61,7 @@ module Mv
|
|
61
61
|
|
62
62
|
def apply_minimum_and_maximum stmt
|
63
63
|
if too_long == too_short
|
64
|
-
[{ statement: "LENGTH(#{stmt}) BETWEEN #{minimum} AND #{maximum}",
|
64
|
+
[{ statement: "LENGTH(#{stmt}) BETWEEN #{minimum} AND #{maximum}",
|
65
65
|
message: message }]
|
66
66
|
else
|
67
67
|
[apply_minimum(stmt), apply_maximum(stmt)].flatten
|
@@ -71,4 +71,4 @@ module Mv
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
|
-
end
|
74
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -6,8 +6,8 @@ module Mv
|
|
6
6
|
module Builder
|
7
7
|
class Uniqueness < Base
|
8
8
|
def conditions
|
9
|
-
res = "NOT EXISTS(SELECT #{column_name}
|
10
|
-
FROM #{table_name}
|
9
|
+
res = "NOT EXISTS(SELECT #{column_name}
|
10
|
+
FROM #{table_name}
|
11
11
|
WHERE #{column_reference} = #{column_name})"
|
12
12
|
|
13
13
|
[{statement: apply_allow_nil_and_blank(res).squish, message: message}]
|
@@ -16,4 +16,4 @@ module Mv
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
|
-
end
|
19
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -7,10 +7,10 @@ module Mv
|
|
7
7
|
attr_reader :statement
|
8
8
|
|
9
9
|
validates :statement, presence: true
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(table_name, column_name, opts)
|
12
12
|
opts = opts.is_a?(Hash) ? opts : { statement: opts }
|
13
|
-
|
13
|
+
|
14
14
|
super(table_name, column_name, opts)
|
15
15
|
|
16
16
|
@statement = opts.with_indifferent_access[:statement]
|
@@ -28,4 +28,4 @@ module Mv
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
@@ -1,29 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'mv/core/validators/array_validator'
|
1
|
+
require_relative 'base_collection'
|
3
2
|
|
4
3
|
module Mv
|
5
4
|
module Core
|
6
5
|
module Validation
|
7
|
-
class Exclusion <
|
8
|
-
include ActiveModel::Validations
|
9
|
-
|
10
|
-
attr_reader :in
|
11
|
-
|
12
|
-
validates :in, presence: true, array: true
|
13
|
-
|
14
|
-
def initialize(table_name, column_name, opts)
|
15
|
-
opts = opts.is_a?(Hash) ? opts : { in: opts }
|
16
|
-
|
17
|
-
super(table_name, column_name, opts)
|
18
|
-
|
19
|
-
@in = opts.with_indifferent_access[:in]
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_a
|
23
|
-
prepared_in = self.in.is_a?(Range) ? [self.in.min, self.in.max] : self.in.try(:sort)
|
24
|
-
super + [prepared_in]
|
25
|
-
end
|
26
|
-
|
6
|
+
class Exclusion < BaseCollection
|
27
7
|
protected
|
28
8
|
|
29
9
|
def default_message
|
@@ -32,4 +12,4 @@ module Mv
|
|
32
12
|
end
|
33
13
|
end
|
34
14
|
end
|
35
|
-
end
|
15
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require 'mv/core/validation/uniqueness'
|
2
|
-
require 'mv/core/validation/exclusion'
|
3
|
-
require 'mv/core/validation/inclusion'
|
4
|
-
require 'mv/core/validation/length'
|
5
|
-
require 'mv/core/validation/presence'
|
6
|
-
require 'mv/core/validation/absence'
|
7
|
-
require 'mv/core/validation/custom'
|
8
1
|
require 'mv/core/error'
|
2
|
+
require_relative 'uniqueness'
|
3
|
+
require_relative 'exclusion'
|
4
|
+
require_relative 'inclusion'
|
5
|
+
require_relative 'length'
|
6
|
+
require_relative 'presence'
|
7
|
+
require_relative 'absence'
|
8
|
+
require_relative 'custom'
|
9
9
|
|
10
10
|
module Mv
|
11
11
|
module Core
|
@@ -16,14 +16,14 @@ module Mv
|
|
16
16
|
def create_validation table_name, column_name, validation_type, opts
|
17
17
|
validation_class = factory_map[validation_type.to_sym]
|
18
18
|
|
19
|
-
raise Mv::Core::Error.new(table_name: table_name,
|
20
|
-
column_name: column_name,
|
21
|
-
validation_type: validation_type,
|
22
|
-
opts: opts,
|
19
|
+
raise Mv::Core::Error.new(table_name: table_name,
|
20
|
+
column_name: column_name,
|
21
|
+
validation_type: validation_type,
|
22
|
+
opts: opts,
|
23
23
|
error: "Validation '#{validation_type}' is not supported") unless validation_class
|
24
24
|
|
25
25
|
validation_class.new(table_name, column_name, opts)
|
26
|
-
end
|
26
|
+
end
|
27
27
|
|
28
28
|
def register_validation validation_type, klass
|
29
29
|
factory_map[validation_type.to_sym] = klass
|
@@ -40,20 +40,20 @@ module Mv
|
|
40
40
|
end
|
41
41
|
|
42
42
|
class << self
|
43
|
-
delegate :create_validation,
|
44
|
-
:registered_validations,
|
43
|
+
delegate :create_validation,
|
44
|
+
:registered_validations,
|
45
45
|
:register_validation,
|
46
46
|
:register_validations, to: :instance
|
47
47
|
end
|
48
48
|
|
49
|
-
private
|
49
|
+
private
|
50
50
|
|
51
51
|
def factory_map
|
52
52
|
@factory_map ||= {
|
53
|
-
uniqueness: Mv::Core::Validation::Uniqueness,
|
54
|
-
exclusion: Mv::Core::Validation::Exclusion,
|
55
|
-
inclusion: Mv::Core::Validation::Inclusion,
|
56
|
-
length: Mv::Core::Validation::Length,
|
53
|
+
uniqueness: Mv::Core::Validation::Uniqueness,
|
54
|
+
exclusion: Mv::Core::Validation::Exclusion,
|
55
|
+
inclusion: Mv::Core::Validation::Inclusion,
|
56
|
+
length: Mv::Core::Validation::Length,
|
57
57
|
presence: Mv::Core::Validation::Presence,
|
58
58
|
absence: Mv::Core::Validation::Absence,
|
59
59
|
custom: Mv::Core::Validation::Custom
|
@@ -62,4 +62,4 @@ module Mv
|
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
|
-
end
|
65
|
+
end
|
@@ -1,29 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'mv/core/validators/array_validator'
|
1
|
+
require_relative 'base_collection'
|
3
2
|
|
4
3
|
module Mv
|
5
4
|
module Core
|
6
5
|
module Validation
|
7
|
-
class Inclusion <
|
8
|
-
include ActiveModel::Validations
|
9
|
-
|
10
|
-
attr_reader :in
|
11
|
-
|
12
|
-
validates :in, presence: true, array: true
|
13
|
-
|
14
|
-
def initialize(table_name, column_name, opts)
|
15
|
-
opts = opts.is_a?(Hash) ? opts : { in: opts }
|
16
|
-
|
17
|
-
super(table_name, column_name, opts)
|
18
|
-
|
19
|
-
@in = opts.with_indifferent_access[:in]
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_a
|
23
|
-
prepared_in = self.in.is_a?(Range) ? [self.in.min, self.in.max] : self.in.try(:sort)
|
24
|
-
super + [prepared_in]
|
25
|
-
end
|
26
|
-
|
6
|
+
class Inclusion < BaseCollection
|
27
7
|
protected
|
28
8
|
|
29
9
|
def default_message
|
@@ -32,4 +12,4 @@ module Mv
|
|
32
12
|
end
|
33
13
|
end
|
34
14
|
end
|
35
|
-
end
|
15
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'mv/core/validation/base'
|
2
1
|
require 'mv/core/validators/integers_array_validator'
|
2
|
+
require_relative 'base'
|
3
3
|
|
4
4
|
module Mv
|
5
5
|
module Core
|
@@ -7,7 +7,7 @@ module Mv
|
|
7
7
|
class Length < Base
|
8
8
|
include ActiveModel::Validations
|
9
9
|
|
10
|
-
attr_reader :in, :within, :is, :maximum, :minimum,
|
10
|
+
attr_reader :in, :within, :is, :maximum, :minimum,
|
11
11
|
:too_long, :too_short
|
12
12
|
|
13
13
|
validates :in, :within, presence: true, allow_nil: true, integers_array: true
|
@@ -16,7 +16,7 @@ module Mv
|
|
16
16
|
validate :in_within_is_maximum_minimum_allowance
|
17
17
|
|
18
18
|
def initialize(table_name, column_name, opts)
|
19
|
-
unless opts.is_a?(Hash)
|
19
|
+
unless opts.is_a?(Hash)
|
20
20
|
opts = { in: opts } if opts.respond_to?(:to_a)
|
21
21
|
opts = { is: opts } if opts.is_a?(Integer)
|
22
22
|
end
|
@@ -42,7 +42,7 @@ module Mv
|
|
42
42
|
too_long ? compose_full_message(too_long) : nil
|
43
43
|
end
|
44
44
|
|
45
|
-
protected
|
45
|
+
protected
|
46
46
|
|
47
47
|
def to_a
|
48
48
|
super + [self.in.try(:sort), within.try(:sort), is.to_s, maximum.to_s, minimum.to_s, too_short.to_s, too_long.to_s]
|
@@ -63,9 +63,9 @@ module Mv
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def in_within_is_maximum_minimum_allowance
|
66
|
-
not_null_attrs = [[is, :is],
|
67
|
-
[within, :within],
|
68
|
-
[self.in, :in],
|
66
|
+
not_null_attrs = [[is, :is],
|
67
|
+
[within, :within],
|
68
|
+
[self.in, :in],
|
69
69
|
[maximum || minimum, :minimum_or_maximum]]
|
70
70
|
.select(&:first).collect(&:second)
|
71
71
|
|
@@ -83,4 +83,4 @@ module Mv
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
-
end
|
86
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require_relative 'base'
|
2
2
|
|
3
3
|
module Mv
|
4
4
|
module Core
|
@@ -14,7 +14,7 @@ module Mv
|
|
14
14
|
opts = opts == true ? {} : opts
|
15
15
|
|
16
16
|
super(table_name, column_name, opts)
|
17
|
-
|
17
|
+
|
18
18
|
@index_name = opts.with_indifferent_access[:index_name] || default_index_name
|
19
19
|
end
|
20
20
|
|
@@ -22,7 +22,7 @@ module Mv
|
|
22
22
|
super + [index_name.to_s]
|
23
23
|
end
|
24
24
|
|
25
|
-
protected
|
25
|
+
protected
|
26
26
|
|
27
27
|
def available_as
|
28
28
|
super + [:index]
|
@@ -48,4 +48,4 @@ module Mv
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,167 +1,167 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mv-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valeriy Prokopchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activerecord
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '5.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '5.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: i18n
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0.7'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: jeweler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: guard-rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '4.5'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '4.5'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '3.1'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '3.1'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rspec-its
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - ~>
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '1.1'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - ~>
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '1.1'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: shoulda
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- - ~>
|
129
|
+
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '3.5'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- - ~>
|
136
|
+
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '3.5'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: factory_girl
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - ~>
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '4.5'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - ~>
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '4.5'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: coveralls
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - ~>
|
157
|
+
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0.7'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - ~>
|
164
|
+
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0.7'
|
167
167
|
description: DB constraints in migrations similiar to ActiveRecord validations. Core
|
@@ -234,6 +234,7 @@ files:
|
|
234
234
|
- lib/mv/core/validation/active_model_presenter/presence.rb
|
235
235
|
- lib/mv/core/validation/active_model_presenter/uniqueness.rb
|
236
236
|
- lib/mv/core/validation/base.rb
|
237
|
+
- lib/mv/core/validation/base_collection.rb
|
237
238
|
- lib/mv/core/validation/builder/absence.rb
|
238
239
|
- lib/mv/core/validation/builder/base.rb
|
239
240
|
- lib/mv/core/validation/builder/custom.rb
|
@@ -263,17 +264,17 @@ require_paths:
|
|
263
264
|
- lib
|
264
265
|
required_ruby_version: !ruby/object:Gem::Requirement
|
265
266
|
requirements:
|
266
|
-
- -
|
267
|
+
- - ">="
|
267
268
|
- !ruby/object:Gem::Version
|
268
|
-
version:
|
269
|
+
version: 2.2.5
|
269
270
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
270
271
|
requirements:
|
271
|
-
- -
|
272
|
+
- - ">="
|
272
273
|
- !ruby/object:Gem::Version
|
273
274
|
version: '0'
|
274
275
|
requirements: []
|
275
276
|
rubyforge_project:
|
276
|
-
rubygems_version: 2.4.
|
277
|
+
rubygems_version: 2.4.5.1
|
277
278
|
signing_key:
|
278
279
|
specification_version: 4
|
279
280
|
summary: DB constraints in migrations similiar to ActiveRecord validations. Core classes
|