anodator 1.0.0.pre1 → 1.0.0.pre2

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.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +3 -0
  3. data/.gitignore +3 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +2 -2
  6. data/README.md +9 -4
  7. data/Rakefile +3 -3
  8. data/anodator.gemspec +17 -14
  9. data/bin/console +3 -3
  10. data/bin/console-on-docker +4 -0
  11. data/bin/docker-console +2 -0
  12. data/bin/docker-prompt +2 -0
  13. data/bin/prompt-on-docker +4 -0
  14. data/bin/setup +0 -0
  15. data/example/example_01.rb +88 -61
  16. data/lib/anodator.rb +3 -2
  17. data/lib/anodator/anodator_error.rb +1 -1
  18. data/lib/anodator/check_result.rb +7 -7
  19. data/lib/anodator/checker.rb +33 -26
  20. data/lib/anodator/common.rb +15 -0
  21. data/lib/anodator/data_source.rb +87 -0
  22. data/lib/anodator/data_source_set.rb +36 -0
  23. data/lib/anodator/input_spec.rb +105 -111
  24. data/lib/anodator/input_spec_item.rb +8 -8
  25. data/lib/anodator/message.rb +14 -14
  26. data/lib/anodator/output_spec.rb +40 -43
  27. data/lib/anodator/rule.rb +26 -32
  28. data/lib/anodator/rule_set.rb +6 -12
  29. data/lib/anodator/utils.rb +36 -42
  30. data/lib/anodator/validator.rb +9 -9
  31. data/lib/anodator/validator/base.rb +44 -27
  32. data/lib/anodator/validator/blank_validator.rb +2 -2
  33. data/lib/anodator/validator/complex_validator.rb +12 -12
  34. data/lib/anodator/validator/configuration_error.rb +1 -2
  35. data/lib/anodator/validator/date_validator.rb +93 -103
  36. data/lib/anodator/validator/format_validator.rb +8 -11
  37. data/lib/anodator/validator/inclusion_validator.rb +3 -3
  38. data/lib/anodator/validator/length_validator.rb +6 -6
  39. data/lib/anodator/validator/numeric_validator.rb +13 -13
  40. data/lib/anodator/validator/presence_validator.rb +2 -2
  41. data/lib/anodator/validator/value_proxy.rb +31 -9
  42. data/lib/anodator/version.rb +1 -1
  43. metadata +41 -6
  44. data/VERSION +0 -1
@@ -1,5 +1,5 @@
1
- require "anodator/validator/base"
2
- require "anodator/validator/configuration_error"
1
+ require 'anodator/validator/base'
2
+ require 'anodator/validator/configuration_error'
3
3
 
4
4
  module Anodator
5
5
  module Validator
@@ -7,29 +7,26 @@ module Anodator
7
7
  ALL_ZENKAKU_REGEXP = /(?:[\xEF\xBD\xA1-\xEF\xBD\xBF]|[\xEF\xBE\x80-\xEF\xBE\x9F])|[\x20-\x7E]/
8
8
 
9
9
  valid_option_keys :format, :all_zenkaku
10
- default_options :all_zenkaku => false
10
+ default_options all_zenkaku: false
11
11
 
12
- def initialize(target_expression, options = { })
12
+ def initialize(target_expression, options = {})
13
13
  super(target_expression, options)
14
14
 
15
15
  if @options[:format].is_a? String
16
- @options[:format] = Regexp.new("#{@options[:format]}")
16
+ @options[:format] = Regexp.new((@options[:format]).to_s)
17
17
  end
18
18
  end
19
19
 
20
20
  def validate
21
21
  if target_value.split(//).size.zero?
22
- if allow_blank?
23
- return true
24
- end
22
+ return true if allow_blank?
25
23
  end
26
24
 
27
-
28
25
  if @options[:all_zenkaku]
29
26
  return target_value !~ ALL_ZENKAKU_REGEXP
30
27
  else
31
28
  unless @options[:format].is_a? Regexp
32
- raise ConfigurationError.new(":format option must be Regexp object")
29
+ raise ConfigurationError, ':format option must be Regexp object'
33
30
  end
34
31
 
35
32
  if @options[:format].match target_value
@@ -41,7 +38,7 @@ module Anodator
41
38
  end
42
39
 
43
40
  def format
44
- return @options[:format].dup
41
+ @options[:format].dup
45
42
  end
46
43
  end
47
44
  end
@@ -1,4 +1,4 @@
1
- require "anodator/validator/base"
1
+ require 'anodator/validator/base'
2
2
 
3
3
  module Anodator
4
4
  module Validator
@@ -11,10 +11,10 @@ module Anodator
11
11
  end
12
12
 
13
13
  unless @options[:in].respond_to? :include?
14
- raise ConfigurationError.new(":in option must be responed_to include?")
14
+ raise ConfigurationError, ':in option must be responed_to include?'
15
15
  end
16
16
 
17
- return @options[:in].include?(target_value)
17
+ @options[:in].include?(target_value)
18
18
  end
19
19
  end
20
20
  end
@@ -1,15 +1,15 @@
1
- require "anodator/validator/base"
2
- require "anodator/validator/configuration_error"
1
+ require 'anodator/validator/base'
2
+ require 'anodator/validator/configuration_error'
3
3
 
4
4
  module Anodator
5
5
  module Validator
6
6
  class LengthValidator < Base
7
7
  valid_option_keys :in, :maximum, :minimum, :is
8
8
 
9
- def initialize(target_expression, options = { })
9
+ def initialize(target_expression, options = {})
10
10
  super(target_expression, options)
11
11
 
12
- [:maximum, :minimum, :is].each do |key|
12
+ %i[maximum minimum is].each do |key|
13
13
  @options[key] = proxy_value(@options[key]) unless @options[key].nil?
14
14
  end
15
15
  end
@@ -27,7 +27,7 @@ module Anodator
27
27
  if configuration.is_a? Range
28
28
  return false unless configuration.include?(length)
29
29
  else
30
- raise ConfigurationError.new(":in option value must be Range object")
30
+ raise ConfigurationError, ':in option value must be Range object'
31
31
  end
32
32
  when :maximum
33
33
  return false if length > configuration.value.to_i
@@ -38,7 +38,7 @@ module Anodator
38
38
  end
39
39
  end
40
40
 
41
- return true
41
+ true
42
42
  end
43
43
  end
44
44
  end
@@ -1,19 +1,19 @@
1
- require "anodator/validator/base"
2
- require "bigdecimal"
1
+ require 'anodator/validator/base'
2
+ require 'bigdecimal'
3
3
 
4
4
  module Anodator
5
5
  module Validator
6
6
  class NumericValidator < Base
7
7
  valid_option_keys :only_integer, :greater_than, :greater_than_or_equal_to
8
8
  valid_option_keys :less_than, :less_than_or_equal_to, :equal_to, :not_equal_to
9
- default_options :only_integer => false
9
+ default_options only_integer: false
10
10
 
11
- def initialize(target_expression, options = { })
11
+ def initialize(target_expression, options = {})
12
12
  super(target_expression, options)
13
13
 
14
- [:greater_than, :greater_than_or_equal_to,
15
- :less_than, :less_than_or_equal_to,
16
- :equal_to, :not_equal_to].each do |key|
14
+ %i[greater_than greater_than_or_equal_to
15
+ less_than less_than_or_equal_to
16
+ equal_to not_equal_to].each do |key|
17
17
  @options[key] = proxy_value(@options[key]) unless @options[key].nil?
18
18
  end
19
19
  end
@@ -24,11 +24,11 @@ module Anodator
24
24
  end
25
25
 
26
26
  # check format
27
- if @options[:only_integer]
28
- regexp = /^-?\d+$/
29
- else
30
- regexp = /^-?\d+(\.\d+)?$/
31
- end
27
+ regexp = if @options[:only_integer]
28
+ /^-?\d+$/
29
+ else
30
+ /^-?\d+(\.\d+)?$/
31
+ end
32
32
  return false unless regexp.match target_value
33
33
 
34
34
  # convert BigDecimal value
@@ -51,7 +51,7 @@ module Anodator
51
51
  end
52
52
  end
53
53
 
54
- return true
54
+ true
55
55
  end
56
56
  end
57
57
  end
@@ -1,4 +1,4 @@
1
- require "anodator/validator/base"
1
+ require 'anodator/validator/base'
2
2
 
3
3
  module Anodator
4
4
  module Validator
@@ -7,7 +7,7 @@ module Anodator
7
7
  # This is the Validator to validate whether the value is present.
8
8
  class PresenceValidator < Base
9
9
  def validate
10
- return !target_value.split(//).size.zero?
10
+ !target_value.split(//).size.zero?
11
11
  end
12
12
  end
13
13
  end
@@ -2,39 +2,61 @@ module Anodator
2
2
  module Validator
3
3
  class ValueProxy
4
4
  REGEXP_INDIRECT = /\A\[\[([^\]]+)\]\]\Z/
5
+ REGEXP_DATA_SOURCE = /\A\{\{([^\}]+)\}\}\Z/
5
6
 
6
7
  def initialize(value, validator)
7
8
  @value = value
8
9
  @validator = validator
9
10
  @indirect = false
11
+ @data_source = false
10
12
 
11
13
  if matched = REGEXP_INDIRECT.match(@value.to_s)
12
14
  @indirect = true
13
15
  @value = matched[1]
14
16
  end
17
+
18
+ if matched = REGEXP_DATA_SOURCE.match(@value.to_s)
19
+ @indirect = true
20
+ @data_source = true
21
+ @value = matched[1].split(':', 3).map do |v|
22
+ ValueProxy.new(v, validator)
23
+ end
24
+ end
15
25
  end
16
26
 
17
27
  def indirect?
18
- return @indirect
28
+ @indirect
19
29
  end
20
30
 
21
31
  def direct?
22
- return !@indirect
32
+ !@indirect
33
+ end
34
+
35
+ def data_source?
36
+ @data_source
23
37
  end
24
38
 
25
39
  def value
26
- if direct?
27
- return @value
28
- else
29
- return @validator.argument_value_at(@value)
40
+ if indirect?
41
+ if data_source?
42
+ @validator.data_source_at(@value[0].value,
43
+ @value[1].value,
44
+ @value[2].value)
45
+ else
46
+ @validator.argument_value_at(@value)
47
+ end
48
+ else # if direct?
49
+ @value
30
50
  end
31
51
  end
32
52
 
33
53
  def to_s
34
- if direct?
35
- return @value.to_s
54
+ if indirect?
55
+ "#{@value}(Indirect)"
56
+ elsif data_source?
57
+ @value.map { |v| v.to_s }.join(':') + '(DataSource)'
36
58
  else
37
- return "#{@value}(Indirect)"
59
+ @value.to_s
38
60
  end
39
61
  end
40
62
  end
@@ -1,3 +1,3 @@
1
1
  module Anodator
2
- VERSION = "1.0.0.pre1"
2
+ VERSION = '1.0.0.pre2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anodator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre1
4
+ version: 1.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tetsuhisa MAKINO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-16 00:00:00.000000000 Z
11
+ date: 2018-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description:
56
84
  email:
57
85
  - tim.makino at gmail.com
@@ -59,6 +87,7 @@ executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
90
+ - ".codeclimate.yml"
62
91
  - ".document"
63
92
  - ".gitignore"
64
93
  - ".rspec"
@@ -68,15 +97,21 @@ files:
68
97
  - README.ja.md
69
98
  - README.md
70
99
  - Rakefile
71
- - VERSION
72
100
  - anodator.gemspec
73
101
  - bin/console
102
+ - bin/console-on-docker
103
+ - bin/docker-console
104
+ - bin/docker-prompt
105
+ - bin/prompt-on-docker
74
106
  - bin/setup
75
107
  - example/example_01.rb
76
108
  - lib/anodator.rb
77
109
  - lib/anodator/anodator_error.rb
78
110
  - lib/anodator/check_result.rb
79
111
  - lib/anodator/checker.rb
112
+ - lib/anodator/common.rb
113
+ - lib/anodator/data_source.rb
114
+ - lib/anodator/data_source_set.rb
80
115
  - lib/anodator/input_spec.rb
81
116
  - lib/anodator/input_spec_item.rb
82
117
  - lib/anodator/message.rb
@@ -107,9 +142,9 @@ require_paths:
107
142
  - lib
108
143
  required_ruby_version: !ruby/object:Gem::Requirement
109
144
  requirements:
110
- - - ">="
145
+ - - "~>"
111
146
  - !ruby/object:Gem::Version
112
- version: '0'
147
+ version: '2.4'
113
148
  required_rubygems_version: !ruby/object:Gem::Requirement
114
149
  requirements:
115
150
  - - ">"
@@ -117,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
152
  version: 1.3.1
118
153
  requirements: []
119
154
  rubyforge_project:
120
- rubygems_version: 2.6.13
155
+ rubygems_version: 2.7.3
121
156
  signing_key:
122
157
  specification_version: 4
123
158
  summary: anodator is Anonymous Data Validator.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.5