otoroshi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/otoroshi/sanctuary.rb +11 -11
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2993a278f341533c1590cd6bdea9291033167104f94018808577f67cbcd2f0ae
4
- data.tar.gz: 725a187567625f428485a80edd5025b0ae7e3a859bebd4d73ea14557353a89ad
3
+ metadata.gz: 125c31a56b83045874e5c91780c2541b93c73a567914917c2b8d54c38650c32d
4
+ data.tar.gz: 45869708d77341f0a45cf3fed38f7719cdd50dac6e13cb7dc528fe36ac2b3f10
5
5
  SHA512:
6
- metadata.gz: c14d31b349b599ff5ef0db40dbaed8723b47bd53de648589ace6ac8ccfeba85b926d263070fe7d13a0746168399508127cd4e3a33df032ff8cfef5d5a9d5380c
7
- data.tar.gz: 19311d09a63ee50e89bd3b3c7dead8faeaba0bd1a4803dfba363c422b0c13704fbeb3bb60799cfac9d681736e209d1587b44be76840bc5736aff4822c6cf9c24
6
+ metadata.gz: 435e9e8988c073ac9c3d8a661c0bdc0030e17118ffb39ca15674b86f6a2ccf9a20d0308a4a126a9c74b0b54aaaee27110e9d6a66d86b99b3f6727f3068484563
7
+ data.tar.gz: d32b924aa3c1446481a2ada3390783881ef1b66a52db41f4e4beb7e72a596e5a854606276443e6f59bad5527fd69c9c3759cb94a84e2d88e1eee9ab1bb6910ac
@@ -5,11 +5,11 @@ module Otoroshi
5
5
  class Sanctuary
6
6
  class << self
7
7
  # Add a new property to the class (called by inherited class)
8
- # Example: property name, type: String, validate: ->(v) { v.length > 3 }, optional: true
9
- def property(name, type = Object, validate: ->(_) { true }, optional: false, default: nil)
8
+ # Example: property name, type: String, validate: ->(v) { v.length > 3 }, allow_nil: true
9
+ def property(name, type = Object, validate: ->(_) { true }, allow_nil: false, default: nil)
10
10
  define_default(name, default)
11
- define_validate_type!(name, type, optional)
12
- define_validate!(name, validate, optional)
11
+ define_validate_type!(name, type, allow_nil)
12
+ define_validate!(name, validate, allow_nil)
13
13
  define_getter(name)
14
14
  define_setter(name)
15
15
  add_to_properties(name)
@@ -49,19 +49,19 @@ module Otoroshi
49
49
  # ::define_validate_type!("score", Integer, false)
50
50
  # ----------------------------------------------
51
51
  # def validate_score_type!(value)
52
- # return if optional && value.nil?
52
+ # return if allow_nil && value.nil?
53
53
  # return if value.is_a?(Integer)
54
54
  #
55
- # raise ArgumentError, ":score does not match type validation"
55
+ # raise ArgumentError, ":score does not match required type"
56
56
  # end
57
57
  #
58
- def define_validate_type!(name, type, optional)
58
+ def define_validate_type!(name, type, allow_nil)
59
59
  lambda = type_validation(type)
60
60
  define_method :"validate_#{name}_type!" do |value|
61
- return if type.nil? || optional && value.nil?
61
+ return if type.nil? || allow_nil && value.nil?
62
62
  return if lambda.call(value)
63
63
 
64
- raise ArgumentError, ":#{name} does not match type validation"
64
+ raise ArgumentError, ":#{name} does not match required type"
65
65
  end
66
66
  private :"validate_#{name}_type!"
67
67
  end
@@ -91,9 +91,9 @@ module Otoroshi
91
91
  # raise ArgumentError, ":score does not match validation"
92
92
  # end
93
93
  #
94
- def define_validate!(name, validate, optional)
94
+ def define_validate!(name, validate, allow_nil)
95
95
  define_method :"validate_#{name}!" do |value|
96
- return if optional && value.nil?
96
+ return if allow_nil && value.nil?
97
97
  return if instance_exec(value, &validate)
98
98
 
99
99
  raise ArgumentError, ":#{name} does not match validation"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otoroshi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Piron