mv-core 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +67 -12
- data/lib/mv-core.rb +18 -100
- data/lib/mv/core/active_record/connection_adapters/abstract_adapter_decorator.rb +51 -0
- data/lib/mv/core/active_record/connection_adapters/table_decorator.rb +13 -0
- data/lib/mv/core/active_record/connection_adapters/table_definition_decorator.rb +21 -0
- data/lib/mv/core/active_record/migration/command_recorder_decorator.rb +13 -0
- data/lib/mv/core/active_record/migration_decorator.rb +14 -0
- data/lib/mv/core/active_record/schema_decorator.rb +16 -0
- data/lib/mv/core/active_record/schema_dumper_decorator.rb +29 -0
- data/lib/mv/core/constraint/base.rb +33 -0
- data/lib/mv/core/constraint/builder/base.rb +45 -0
- data/lib/mv/core/constraint/builder/factory.rb +42 -0
- data/lib/mv/core/constraint/builder/index.rb +50 -0
- data/lib/mv/core/constraint/builder/trigger.rb +13 -0
- data/lib/mv/core/constraint/description.rb +24 -0
- data/lib/mv/core/constraint/factory.rb +33 -0
- data/lib/mv/core/constraint/index.rb +13 -0
- data/lib/mv/core/constraint/trigger.rb +20 -0
- data/lib/mv/core/db/helpers/column_validators.rb +57 -0
- data/lib/mv/core/db/helpers/table_validators.rb +38 -0
- data/lib/mv/core/db/migration_validator.rb +26 -0
- data/lib/mv/core/error.rb +25 -0
- data/lib/mv/core/migration/base.rb +94 -0
- data/lib/mv/core/migration/operations/add_column.rb +27 -0
- data/lib/mv/core/migration/operations/change_column.rb +31 -0
- data/lib/mv/core/migration/operations/drop_table.rb +21 -0
- data/lib/mv/core/migration/operations/factory.rb +20 -0
- data/lib/mv/core/migration/operations/list.rb +28 -0
- data/lib/mv/core/migration/operations/remove_column.rb +22 -0
- data/lib/mv/core/migration/operations/rename_column.rb +26 -0
- data/lib/mv/core/migration/operations/rename_table.rb +25 -0
- data/lib/mv/core/presenter/constraint/description.rb +26 -0
- data/lib/mv/core/presenter/validation/base.rb +73 -0
- data/lib/mv/core/railtie.rb +40 -0
- data/lib/mv/core/route/base.rb +25 -0
- data/lib/mv/core/route/index.rb +17 -0
- data/lib/mv/core/route/trigger.rb +22 -0
- data/lib/mv/core/router.rb +33 -0
- data/lib/mv/core/services/compare_constraint_arrays.rb +50 -0
- data/lib/mv/core/services/compare_constraints.rb +31 -0
- data/lib/mv/core/services/create_constraints.rb +30 -0
- data/lib/mv/core/services/create_migration_validators_table.rb +31 -0
- data/lib/mv/core/services/delete_constraints.rb +30 -0
- data/lib/mv/core/services/load_constraints.rb +45 -0
- data/lib/mv/core/services/say_constraints_diff.rb +66 -0
- data/lib/mv/core/services/show_constraints.rb +41 -0
- data/lib/mv/core/services/synchronize_constraints.rb +54 -0
- data/lib/mv/core/services/uninstall.rb +25 -0
- data/lib/mv/core/validation/absence.rb +35 -0
- data/lib/mv/core/validation/base.rb +98 -0
- data/lib/mv/core/validation/builder/absence.rb +19 -0
- data/lib/mv/core/validation/builder/base.rb +58 -0
- data/lib/mv/core/validation/builder/exclusion.rb +42 -0
- data/lib/mv/core/validation/builder/factory.rb +43 -0
- data/lib/mv/core/validation/builder/inclusion.rb +42 -0
- data/lib/mv/core/validation/builder/length.rb +68 -0
- data/lib/mv/core/validation/builder/presence.rb +19 -0
- data/lib/mv/core/validation/builder/uniqueness.rb +19 -0
- data/lib/mv/core/validation/exclusion.rb +27 -0
- data/lib/mv/core/validation/factory.rb +56 -0
- data/lib/mv/core/validation/inclusion.rb +27 -0
- data/lib/mv/core/validation/length.rb +59 -0
- data/lib/mv/core/validation/presence.rb +25 -0
- data/lib/mv/core/validation/uniqueness.rb +45 -0
- data/lib/mv/core/validators/array_validator.rb +5 -0
- data/lib/mv/core/validators/integers_array_validator.rb +12 -0
- data/lib/mv/core/validators/valid_validator.rb +9 -0
- metadata +158 -30
- data/lib/migration_validators/active_record/base.rb +0 -29
- data/lib/migration_validators/active_record/connection_adapters/abstract_adapter.rb +0 -38
- data/lib/migration_validators/active_record/connection_adapters/native_adapter.rb +0 -129
- data/lib/migration_validators/active_record/connection_adapters/table.rb +0 -17
- data/lib/migration_validators/active_record/connection_adapters/table_definition.rb +0 -33
- data/lib/migration_validators/active_record/migration.rb +0 -25
- data/lib/migration_validators/active_record/schema.rb +0 -32
- data/lib/migration_validators/active_record/schema_dumper.rb +0 -25
- data/lib/migration_validators/adapters/base.rb +0 -15
- data/lib/migration_validators/adapters/containers.rb +0 -100
- data/lib/migration_validators/adapters/routing.rb +0 -102
- data/lib/migration_validators/adapters/syntax.rb +0 -51
- data/lib/migration_validators/adapters/validator_definitions.rb +0 -132
- data/lib/migration_validators/core/adapter_wrapper.rb +0 -88
- data/lib/migration_validators/core/db_validator.rb +0 -131
- data/lib/migration_validators/core/statement_builder.rb +0 -61
- data/lib/migration_validators/core/validator_constraints_list.rb +0 -32
- data/lib/migration_validators/core/validator_container.rb +0 -110
- data/lib/migration_validators/core/validator_definition.rb +0 -91
- data/lib/migration_validators/core/validator_router.rb +0 -45
- data/lib/options.rb +0 -7
@@ -1,61 +0,0 @@
|
|
1
|
-
module MigrationValidators
|
2
|
-
module Core
|
3
|
-
class StatementBuilder
|
4
|
-
attr_reader :actions
|
5
|
-
|
6
|
-
def initialize value = "", builder = nil
|
7
|
-
@stmt = value
|
8
|
-
@actions = builder ? builder.actions.clone : {}
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
@stmt
|
13
|
-
end
|
14
|
-
|
15
|
-
def operation name, &block
|
16
|
-
@actions[name.to_s] = block || lambda{|stmt| stmt}
|
17
|
-
end
|
18
|
-
|
19
|
-
def compile value
|
20
|
-
StatementBuilder.new value, self
|
21
|
-
end
|
22
|
-
|
23
|
-
def merge! builder
|
24
|
-
@actions.merge!(builder.actions) if builder
|
25
|
-
self
|
26
|
-
end
|
27
|
-
|
28
|
-
alias_method :old_method_missing, :method_missing
|
29
|
-
def method_missing method_name, *args
|
30
|
-
call_action(method_name, *args) || old_method_missing(method_name, *args)
|
31
|
-
end
|
32
|
-
|
33
|
-
protected
|
34
|
-
|
35
|
-
|
36
|
-
attr_accessor :stmt
|
37
|
-
|
38
|
-
def clear!
|
39
|
-
@stmt = ""
|
40
|
-
end
|
41
|
-
|
42
|
-
def change *args, &block
|
43
|
-
@stmt = instance_exec(*args, &block).to_s
|
44
|
-
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def call_action action_name, *args
|
49
|
-
block = @actions[action_name.to_s]
|
50
|
-
|
51
|
-
if (block)
|
52
|
-
change(@stmt, *args, &block)
|
53
|
-
return self
|
54
|
-
end
|
55
|
-
|
56
|
-
return nil
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module MigrationValidators
|
2
|
-
module Core
|
3
|
-
class ValidatorConstraintsList
|
4
|
-
attr_reader :raw_list
|
5
|
-
|
6
|
-
def initialize *constraints
|
7
|
-
@raw_list = constraints.collect(&:to_s)
|
8
|
-
end
|
9
|
-
|
10
|
-
def add constraint
|
11
|
-
@raw_list << constraint.to_s
|
12
|
-
@raw_list.uniq!
|
13
|
-
end
|
14
|
-
|
15
|
-
def remove constraint
|
16
|
-
@raw_list.delete(constraint.to_s)
|
17
|
-
end
|
18
|
-
|
19
|
-
def include? constraint
|
20
|
-
@raw_list.include?(constraint.to_s)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.load(raw_list)
|
24
|
-
new(*(YAML.load(raw_list || "") || []))
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.dump(list)
|
28
|
-
YAML.dump(list.raw_list)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
module MigrationValidators
|
2
|
-
module Core
|
3
|
-
class ValidatorContainer < StatementBuilder
|
4
|
-
attr_reader :name
|
5
|
-
|
6
|
-
def initialize name, definitions, builder = nil
|
7
|
-
super "", builder
|
8
|
-
|
9
|
-
@name = name
|
10
|
-
@definitions = definitions
|
11
|
-
|
12
|
-
group do |validator|
|
13
|
-
validator.name
|
14
|
-
end
|
15
|
-
|
16
|
-
constraint_name do |group_key|
|
17
|
-
group_key.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
operation :create do |stmt, group_name|
|
21
|
-
stmt
|
22
|
-
end
|
23
|
-
|
24
|
-
operation :drop do
|
25
|
-
""
|
26
|
-
end
|
27
|
-
|
28
|
-
operation :join do |stmt, stmt_1|
|
29
|
-
[stmt, stmt_1].delete_if(&:blank?).join(" JOIN ")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def group &block
|
34
|
-
@group_proc = block
|
35
|
-
end
|
36
|
-
|
37
|
-
def constraint_name &block
|
38
|
-
@constraint_name_proc = block
|
39
|
-
end
|
40
|
-
|
41
|
-
def add_validators validators
|
42
|
-
res, constraint_name = process_validators(validators) do |existing_validators|
|
43
|
-
validators + existing_validators
|
44
|
-
end
|
45
|
-
|
46
|
-
validators.each {|validator| validator.constraints.add(constraint_name) }
|
47
|
-
|
48
|
-
res
|
49
|
-
end
|
50
|
-
|
51
|
-
def remove_validators validators
|
52
|
-
res, constraint_name = process_validators(validators) do |existing_validators|
|
53
|
-
existing_validators - validators
|
54
|
-
end
|
55
|
-
|
56
|
-
validators.each {|validator| validator.constraints.remove(constraint_name) }
|
57
|
-
|
58
|
-
res
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def process_validators validators
|
64
|
-
validators.group_by(&@group_proc).inject([]) do |res, (group_name, group)|
|
65
|
-
constraint_name = @constraint_name_proc.call(group_name)
|
66
|
-
constraint_validators = MigrationValidators::Core::DbValidator.constraint_validators(constraint_name)
|
67
|
-
|
68
|
-
group = yield(constraint_validators).uniq
|
69
|
-
|
70
|
-
stmt = drop_group(constraint_name, group_name)
|
71
|
-
res << stmt unless stmt.blank?
|
72
|
-
|
73
|
-
unless group.blank?
|
74
|
-
stmt = create_group(constraint_name, group_name, group)
|
75
|
-
res << stmt unless stmt.blank?
|
76
|
-
end
|
77
|
-
[res, constraint_name]
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def isolate
|
82
|
-
clear!
|
83
|
-
yield if block_given?
|
84
|
-
res = self.to_s
|
85
|
-
clear!
|
86
|
-
res
|
87
|
-
end
|
88
|
-
|
89
|
-
def drop_group constraint_name, group_name
|
90
|
-
isolate { drop(constraint_name, group_name) }
|
91
|
-
end
|
92
|
-
|
93
|
-
def create_group constraint_name, group_name, group
|
94
|
-
isolate do
|
95
|
-
group.each do |validator|
|
96
|
-
definition = @definitions[validator.validator_name.to_s] || @definitions[validator.validator_name.to_sym]
|
97
|
-
|
98
|
-
raise MigrationValidators::MigrationValidatorsException.new("Validator defintion for #{validator.validator_name} is not defined.") unless definition
|
99
|
-
|
100
|
-
definition.clone(self).process(validator).each do |statement|
|
101
|
-
join(statement)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
create(constraint_name, group_name) unless group.blank?
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
module MigrationValidators
|
2
|
-
module Core
|
3
|
-
class ValidatorDefinition < StatementBuilder
|
4
|
-
attr_reader :validator
|
5
|
-
|
6
|
-
def initialize definition = nil, validator = nil, properties = {}, posts = []
|
7
|
-
super "", definition
|
8
|
-
|
9
|
-
@properties = properties
|
10
|
-
@posts = posts
|
11
|
-
|
12
|
-
self.validator = validator if validator
|
13
|
-
|
14
|
-
operation :bind_to_error do |stmt, error|
|
15
|
-
stmt
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def validator= validator
|
20
|
-
@validator = validator
|
21
|
-
@stmt = validator.column_name
|
22
|
-
end
|
23
|
-
|
24
|
-
def column
|
25
|
-
clone
|
26
|
-
end
|
27
|
-
|
28
|
-
def clone builder = nil
|
29
|
-
res = ValidatorDefinition.new self, validator, @properties.clone, @posts.clone
|
30
|
-
res.merge!(builder) if builder
|
31
|
-
res
|
32
|
-
end
|
33
|
-
|
34
|
-
def property name = "", opts = {}, &block
|
35
|
-
@properties[name.to_s] ||= [opts, block]
|
36
|
-
end
|
37
|
-
|
38
|
-
def post opts = {}, &block
|
39
|
-
@posts << [opts, block]
|
40
|
-
end
|
41
|
-
|
42
|
-
def process validator, filter = []
|
43
|
-
self.validator = validator
|
44
|
-
|
45
|
-
return [] if validator.options.nil?
|
46
|
-
|
47
|
-
unless filter.blank?
|
48
|
-
filter = filter.collect(&:to_s)
|
49
|
-
options = validator.options.select{|name, value| filter.include?(name.to_s) }
|
50
|
-
else
|
51
|
-
options = validator.options
|
52
|
-
end
|
53
|
-
|
54
|
-
res = options.inject([]) do |res, (property_name, property_value)|
|
55
|
-
res << self.to_s if handle_property(property_name, property_value)
|
56
|
-
res
|
57
|
-
end
|
58
|
-
|
59
|
-
return res unless res.blank?
|
60
|
-
return (handle_property("", options) && res << self.to_s) || []
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
def handle_property property_name, property_value
|
66
|
-
opts, block = @properties[property_name.to_s]
|
67
|
-
|
68
|
-
if (block)
|
69
|
-
# at_least_one_property_handled = true
|
70
|
-
change(property_value, &block)
|
71
|
-
apply_posts
|
72
|
-
bind_to_error(message(opts))
|
73
|
-
|
74
|
-
return true
|
75
|
-
end
|
76
|
-
|
77
|
-
false
|
78
|
-
end
|
79
|
-
|
80
|
-
def apply_posts
|
81
|
-
@posts.each{|opts, post_block| change(&post_block) if validator.satisfies(opts)}
|
82
|
-
end
|
83
|
-
|
84
|
-
def message opts
|
85
|
-
validator.options[opts[:message]] ||
|
86
|
-
validator.options[:message] ||
|
87
|
-
validator.error_message
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module MigrationValidators
|
2
|
-
module Core
|
3
|
-
class ValidatorRouter
|
4
|
-
def initialize containers
|
5
|
-
@containers = containers
|
6
|
-
@routes = {}
|
7
|
-
end
|
8
|
-
|
9
|
-
def to container_name, conditions = {}
|
10
|
-
raise "Container name is undefined" if container_name.blank?
|
11
|
-
|
12
|
-
@routes[container_name] ||= conditions[:if]
|
13
|
-
end
|
14
|
-
|
15
|
-
def add_validators validators
|
16
|
-
process(validators) do |container, filtered_validators|
|
17
|
-
container.add_validators(filtered_validators)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def remove_validators validators
|
22
|
-
process(validators) do |container, filtered_validators|
|
23
|
-
container.remove_validators(filtered_validators)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def process validators
|
30
|
-
@routes.inject([]) do |res, (container_name, conditions)|
|
31
|
-
filtered_validators = validators.select {|validator| validator.satisfies(conditions)}
|
32
|
-
|
33
|
-
unless filtered_validators.blank?
|
34
|
-
container = @containers[container_name]
|
35
|
-
raise MigrationValidators::MigrationValidatorsException.new("Routing error. Contianer #{container_name} is not defined.") if container.nil?
|
36
|
-
|
37
|
-
res.concat(yield(container, filtered_validators))
|
38
|
-
end
|
39
|
-
|
40
|
-
res
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|