mv-mysql 2.2.1 → 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +102 -0
- data/lib/mv-mysql.rb +0 -66
- data/lib/mv/mysql/loader.rb +65 -0
- data/lib/mv/mysql/railtie.rb +5 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1cc68c185a5299f5c76cfe82688f2b75567f694
|
4
|
+
data.tar.gz: c35366ad8e92924a6ed1cbcb95261be155be26fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6b215675ad6937197abe5806428f214e9cb852a542acc6507d3adc3ca2fd8b352fe0988ff4e868d311b5ab3b2dfc0bff8fe91c0ff260189fb9a5cdd15d5c0ca
|
7
|
+
data.tar.gz: ebf84711da807433df3bd2f8068eaf4e116565574c6b9d3cf9bbf144ae7a1d99fc2052e607af9f6e52a50403501f59c52d06c42cb1c6bd7d2438aaf793d2c03f
|
data/README.md
CHANGED
@@ -14,6 +14,7 @@ Define validations directly in DB as MySQL constraints and integrate them into y
|
|
14
14
|
* [exclusion](#exclusion)
|
15
15
|
* [presence](#presence)
|
16
16
|
* [absence](#absence)
|
17
|
+
* [format](#format)
|
17
18
|
* [custom](#custom)
|
18
19
|
* [Version History](#version history)
|
19
20
|
* [Contributing](#contributing)
|
@@ -538,6 +539,99 @@ Define validations directly in DB as MySQL constraints and integrate them into y
|
|
538
539
|
* `allow_blank` - ignore validation for blank values. Default value: `true`
|
539
540
|
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger]` Default value: `:trigger`
|
540
541
|
|
542
|
+
|
543
|
+
### format
|
544
|
+
|
545
|
+
Examples:
|
546
|
+
|
547
|
+
allows only values that contains 'word' inside:
|
548
|
+
|
549
|
+
```ruby
|
550
|
+
def up
|
551
|
+
validates :table_name, :column_name, format: { with: /word/ }
|
552
|
+
end
|
553
|
+
|
554
|
+
def down
|
555
|
+
validates :table_name, :column_name, format: false
|
556
|
+
end
|
557
|
+
```
|
558
|
+
|
559
|
+
with failure message:
|
560
|
+
|
561
|
+
```ruby
|
562
|
+
def up
|
563
|
+
validates :table_name, :column_name,
|
564
|
+
format: { with: /word/,
|
565
|
+
message: 'Column_name value should contain start word' }
|
566
|
+
end
|
567
|
+
|
568
|
+
def down
|
569
|
+
validates :table_name, :column_name, format: false
|
570
|
+
end
|
571
|
+
```
|
572
|
+
|
573
|
+
implemented as trigger:
|
574
|
+
|
575
|
+
```ruby
|
576
|
+
def up
|
577
|
+
validates :table_name, :column_name,
|
578
|
+
format: { with: /word/,
|
579
|
+
message: 'Column_name value should contain start word',
|
580
|
+
as: :trigger }
|
581
|
+
end
|
582
|
+
|
583
|
+
def down
|
584
|
+
validates :table_name, :column_name, format: false
|
585
|
+
end
|
586
|
+
```
|
587
|
+
|
588
|
+
all above are available in a create and change table blocks:
|
589
|
+
|
590
|
+
```ruby
|
591
|
+
def change
|
592
|
+
create_table :table_name do |t|
|
593
|
+
t.string :column_name, validates { format: { with: /word/ } }
|
594
|
+
end
|
595
|
+
end
|
596
|
+
```
|
597
|
+
|
598
|
+
```ruby
|
599
|
+
def up
|
600
|
+
change :table_name do |t|
|
601
|
+
t.change :column_name, :string, validates: { format: { with: /word/ } }
|
602
|
+
end
|
603
|
+
end
|
604
|
+
|
605
|
+
def down
|
606
|
+
change :table_name do |t|
|
607
|
+
t.change :column_name, :string, validates: { format: false }
|
608
|
+
end
|
609
|
+
end
|
610
|
+
```
|
611
|
+
|
612
|
+
simplifications (version >= 2.1 is required):
|
613
|
+
|
614
|
+
```ruby
|
615
|
+
def change
|
616
|
+
create_table :table_name do |t|
|
617
|
+
t.string :contains_word, format: /word/
|
618
|
+
t.string :contains_word_in_trigger, format: { with: /word/,
|
619
|
+
as: :trigger }
|
620
|
+
end
|
621
|
+
end
|
622
|
+
```
|
623
|
+
|
624
|
+
Options:
|
625
|
+
|
626
|
+
* `with` - regular expression that column value should be matched to
|
627
|
+
* `message` - message that should be shown if validation failed
|
628
|
+
* `on` - validation event. Possible values `[:save, :update, :create]`. Ignored unless `:as == :trigger`. Default value: `:save`
|
629
|
+
* `create_tigger_name` - Name of the 'before insert' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :create]`
|
630
|
+
* `update_tigger_name` - Name of the 'before update' trigger that will be created if `:as == :trigger` && `:on` in `[:save, :update]`
|
631
|
+
* `allow_nil` - ignore validation for `nil` values. Default value: `false`
|
632
|
+
* `allow_blank` - ignore validation for blank values. Default value: `false`
|
633
|
+
* `as` - defines the way how constraint will be implemented. Possible values: `[:trigger]` Default value: `:trigger`
|
634
|
+
|
541
635
|
### custom
|
542
636
|
|
543
637
|
(version >= 2.1 is required)
|
@@ -651,6 +745,14 @@ Define validations directly in DB as MySQL constraints and integrate them into y
|
|
651
745
|
|
652
746
|
* Integration with ActiveRecord
|
653
747
|
|
748
|
+
**(2.2.1)** (23 May, 2015)
|
749
|
+
|
750
|
+
* Format validation
|
751
|
+
|
752
|
+
**(2.2.2)** (29 May, 2015)
|
753
|
+
|
754
|
+
* Made it possible to use several mv-* drivers in the same project
|
755
|
+
|
654
756
|
## Contributing
|
655
757
|
|
656
758
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/lib/mv-mysql.rb
CHANGED
@@ -1,68 +1,2 @@
|
|
1
1
|
require 'mv-core'
|
2
2
|
require 'mv/mysql/railtie'
|
3
|
-
|
4
|
-
require 'mv/mysql/constraint/builder/trigger'
|
5
|
-
|
6
|
-
require 'mv/mysql/validation/exclusion'
|
7
|
-
require 'mv/mysql/validation/inclusion'
|
8
|
-
require 'mv/mysql/validation/length'
|
9
|
-
require 'mv/mysql/validation/presence'
|
10
|
-
require 'mv/mysql/validation/absence'
|
11
|
-
require 'mv/mysql/validation/uniqueness'
|
12
|
-
require 'mv/mysql/validation/format'
|
13
|
-
require 'mv/mysql/validation/custom'
|
14
|
-
|
15
|
-
require 'mv/mysql/validation/builder/trigger/exclusion'
|
16
|
-
require 'mv/mysql/validation/builder/trigger/inclusion'
|
17
|
-
require 'mv/mysql/validation/builder/trigger/length'
|
18
|
-
require 'mv/mysql/validation/builder/trigger/presence'
|
19
|
-
require 'mv/mysql/validation/builder/trigger/absence'
|
20
|
-
require 'mv/mysql/validation/builder/trigger/uniqueness'
|
21
|
-
require 'mv/mysql/validation/builder/trigger/format'
|
22
|
-
require 'mv/mysql/validation/builder/trigger/custom'
|
23
|
-
|
24
|
-
require 'mv/mysql/validation/active_model_presenter/format'
|
25
|
-
|
26
|
-
ActiveSupport.on_load(:mv_core) do
|
27
|
-
|
28
|
-
#constraint builders
|
29
|
-
Mv::Core::Constraint::Builder::Factory.register_builders(
|
30
|
-
Mv::Core::Constraint::Trigger => Mv::Mysql::Constraint::Builder::Trigger,
|
31
|
-
)
|
32
|
-
|
33
|
-
#validations
|
34
|
-
Mv::Core::Validation::Factory.register_validations(
|
35
|
-
:exclusion => Mv::Mysql::Validation::Exclusion,
|
36
|
-
:inclusion => Mv::Mysql::Validation::Inclusion,
|
37
|
-
:length => Mv::Mysql::Validation::Length,
|
38
|
-
:presence => Mv::Mysql::Validation::Presence,
|
39
|
-
:absence => Mv::Mysql::Validation::Absence,
|
40
|
-
:uniqueness => Mv::Mysql::Validation::Uniqueness,
|
41
|
-
:format => Mv::Mysql::Validation::Format,
|
42
|
-
:custom => Mv::Mysql::Validation::Custom
|
43
|
-
)
|
44
|
-
|
45
|
-
# validation builders in trigger
|
46
|
-
Mv::Mysql::Constraint::Builder::Trigger.validation_builders_factory.register_builders(
|
47
|
-
Mv::Mysql::Validation::Exclusion => Mv::Mysql::Validation::Builder::Trigger::Exclusion,
|
48
|
-
Mv::Mysql::Validation::Inclusion => Mv::Mysql::Validation::Builder::Trigger::Inclusion,
|
49
|
-
Mv::Mysql::Validation::Length => Mv::Mysql::Validation::Builder::Trigger::Length,
|
50
|
-
Mv::Mysql::Validation::Presence => Mv::Mysql::Validation::Builder::Trigger::Presence,
|
51
|
-
Mv::Mysql::Validation::Absence => Mv::Mysql::Validation::Builder::Trigger::Absence,
|
52
|
-
Mv::Mysql::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness,
|
53
|
-
Mv::Mysql::Validation::Format => Mv::Mysql::Validation::Builder::Trigger::Format,
|
54
|
-
Mv::Mysql::Validation::Custom => Mv::Mysql::Validation::Builder::Trigger::Custom
|
55
|
-
)
|
56
|
-
|
57
|
-
#validation active model presenters
|
58
|
-
Mv::Core::Validation::ActiveModelPresenter::Factory.register_presenters(
|
59
|
-
Mv::Mysql::Validation::Exclusion => Mv::Core::Validation::ActiveModelPresenter::Exclusion,
|
60
|
-
Mv::Mysql::Validation::Inclusion => Mv::Core::Validation::ActiveModelPresenter::Inclusion,
|
61
|
-
Mv::Mysql::Validation::Length => Mv::Core::Validation::ActiveModelPresenter::Length,
|
62
|
-
Mv::Mysql::Validation::Presence => Mv::Core::Validation::ActiveModelPresenter::Presence,
|
63
|
-
Mv::Mysql::Validation::Absence => Mv::Core::Validation::ActiveModelPresenter::Absence,
|
64
|
-
Mv::Mysql::Validation::Uniqueness => Mv::Core::Validation::ActiveModelPresenter::Uniqueness,
|
65
|
-
Mv::Mysql::Validation::Format => Mv::Mysql::Validation::ActiveModelPresenter::Format
|
66
|
-
)
|
67
|
-
end
|
68
|
-
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'mv/mysql/constraint/builder/trigger'
|
2
|
+
|
3
|
+
require 'mv/mysql/validation/exclusion'
|
4
|
+
require 'mv/mysql/validation/inclusion'
|
5
|
+
require 'mv/mysql/validation/length'
|
6
|
+
require 'mv/mysql/validation/presence'
|
7
|
+
require 'mv/mysql/validation/absence'
|
8
|
+
require 'mv/mysql/validation/uniqueness'
|
9
|
+
require 'mv/mysql/validation/format'
|
10
|
+
require 'mv/mysql/validation/custom'
|
11
|
+
|
12
|
+
require 'mv/mysql/validation/builder/trigger/exclusion'
|
13
|
+
require 'mv/mysql/validation/builder/trigger/inclusion'
|
14
|
+
require 'mv/mysql/validation/builder/trigger/length'
|
15
|
+
require 'mv/mysql/validation/builder/trigger/presence'
|
16
|
+
require 'mv/mysql/validation/builder/trigger/absence'
|
17
|
+
require 'mv/mysql/validation/builder/trigger/uniqueness'
|
18
|
+
require 'mv/mysql/validation/builder/trigger/format'
|
19
|
+
require 'mv/mysql/validation/builder/trigger/custom'
|
20
|
+
|
21
|
+
require 'mv/mysql/validation/active_model_presenter/format'
|
22
|
+
|
23
|
+
require 'mv/mysql/active_record/connection_adapters/mysql_adapter_decorator'
|
24
|
+
|
25
|
+
#constraint builders
|
26
|
+
Mv::Core::Constraint::Builder::Factory.register_builders(
|
27
|
+
Mv::Core::Constraint::Trigger => Mv::Mysql::Constraint::Builder::Trigger,
|
28
|
+
)
|
29
|
+
|
30
|
+
#validations
|
31
|
+
Mv::Core::Validation::Factory.register_validations(
|
32
|
+
:exclusion => Mv::Mysql::Validation::Exclusion,
|
33
|
+
:inclusion => Mv::Mysql::Validation::Inclusion,
|
34
|
+
:length => Mv::Mysql::Validation::Length,
|
35
|
+
:presence => Mv::Mysql::Validation::Presence,
|
36
|
+
:absence => Mv::Mysql::Validation::Absence,
|
37
|
+
:uniqueness => Mv::Mysql::Validation::Uniqueness,
|
38
|
+
:format => Mv::Mysql::Validation::Format,
|
39
|
+
:custom => Mv::Mysql::Validation::Custom
|
40
|
+
)
|
41
|
+
|
42
|
+
# validation builders in trigger
|
43
|
+
Mv::Mysql::Constraint::Builder::Trigger.validation_builders_factory.register_builders(
|
44
|
+
Mv::Mysql::Validation::Exclusion => Mv::Mysql::Validation::Builder::Trigger::Exclusion,
|
45
|
+
Mv::Mysql::Validation::Inclusion => Mv::Mysql::Validation::Builder::Trigger::Inclusion,
|
46
|
+
Mv::Mysql::Validation::Length => Mv::Mysql::Validation::Builder::Trigger::Length,
|
47
|
+
Mv::Mysql::Validation::Presence => Mv::Mysql::Validation::Builder::Trigger::Presence,
|
48
|
+
Mv::Mysql::Validation::Absence => Mv::Mysql::Validation::Builder::Trigger::Absence,
|
49
|
+
Mv::Mysql::Validation::Uniqueness => Mv::Mysql::Validation::Builder::Trigger::Uniqueness,
|
50
|
+
Mv::Mysql::Validation::Format => Mv::Mysql::Validation::Builder::Trigger::Format,
|
51
|
+
Mv::Mysql::Validation::Custom => Mv::Mysql::Validation::Builder::Trigger::Custom
|
52
|
+
)
|
53
|
+
|
54
|
+
#validation active model presenters
|
55
|
+
Mv::Core::Validation::ActiveModelPresenter::Factory.register_presenters(
|
56
|
+
Mv::Mysql::Validation::Exclusion => Mv::Core::Validation::ActiveModelPresenter::Exclusion,
|
57
|
+
Mv::Mysql::Validation::Inclusion => Mv::Core::Validation::ActiveModelPresenter::Inclusion,
|
58
|
+
Mv::Mysql::Validation::Length => Mv::Core::Validation::ActiveModelPresenter::Length,
|
59
|
+
Mv::Mysql::Validation::Presence => Mv::Core::Validation::ActiveModelPresenter::Presence,
|
60
|
+
Mv::Mysql::Validation::Absence => Mv::Core::Validation::ActiveModelPresenter::Absence,
|
61
|
+
Mv::Mysql::Validation::Uniqueness => Mv::Core::Validation::ActiveModelPresenter::Uniqueness,
|
62
|
+
Mv::Mysql::Validation::Format => Mv::Mysql::Validation::ActiveModelPresenter::Format
|
63
|
+
)
|
64
|
+
|
65
|
+
::ActiveRecord::ConnectionAdapters::Mysql2Adapter.send(:prepend, Mv::Mysql::ActiveRecord::ConnectionAdapters::MysqlAdapterDecorator)
|
data/lib/mv/mysql/railtie.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
require 'mv/mysql/active_record/connection_adapters/mysql_adapter_decorator'
|
2
|
-
|
3
1
|
module Mv
|
4
2
|
module Mysql
|
5
3
|
class Railtie < ::Rails::Railtie
|
6
4
|
initializer 'mv-mysql.initialization', after: 'active_record.initialize_database' do
|
7
|
-
::ActiveRecord::ConnectionAdapters::Mysql2Adapter
|
5
|
+
if defined?(::ActiveRecord::ConnectionAdapters::Mysql2Adapter) &&
|
6
|
+
::ActiveRecord::Base.connection.is_a?(::ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
7
|
+
require 'mv/mysql/loader'
|
8
|
+
end
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
11
|
-
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mv-mysql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valeriy Prokopchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/mv-mysql.rb
|
136
136
|
- lib/mv/mysql/active_record/connection_adapters/mysql_adapter_decorator.rb
|
137
137
|
- lib/mv/mysql/constraint/builder/trigger.rb
|
138
|
+
- lib/mv/mysql/loader.rb
|
138
139
|
- lib/mv/mysql/railtie.rb
|
139
140
|
- lib/mv/mysql/validation/absence.rb
|
140
141
|
- lib/mv/mysql/validation/active_model_presenter/format.rb
|