otoroshi 0.0.5 → 0.0.6

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/otoroshi/sanctuary.rb +32 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b84f923c9c4e6ea666ec899e051c3e58deff635fe00a8fe116faff2dd0c81b3
4
- data.tar.gz: 34899b93e6efa7e257821b553ea4ae9d84510b47734a396e7674cf540e6ded9b
3
+ metadata.gz: e31c6e00090297fb9709600d1580a24a4729ee1a9af094015ea7c197fde884d3
4
+ data.tar.gz: 033526ab6473e809a19c812104cf05cadba29485d617161c1799f6664777f9fc
5
5
  SHA512:
6
- metadata.gz: c44a2deba36e4ab2faf479162c40fba26643a5aab8666e1e2a7b287ce4fc4d33ab1b41f33639f5bd5b6b93a26891c663a00af971e50160a40bdee3df49997c63
7
- data.tar.gz: f4893e22addea6e851d6a6fc21eb6d5c5188a95c66f52e12b16ff44afc3a9340b33bf3aa472d3962bad572e42f412028d0887d6f5bf09d71efb435e66a84a848
6
+ metadata.gz: a5e9595b7c246dde6897fc4f314cdf0c9ef00576dd042cc9c4e34c60de249d4d346ebc2f661f1190708a26211cacbdd1a9f457a9e5802e57049b5f5d831dc9d1
7
+ data.tar.gz: 42aace4283c39b3d956022e643635d73a9b3a5feb74070f0dd441d8ef165b5d9c76475a7bd274b94e4da8f85aa0ecb08868116842c6af98b1cdf4112a93bbe77
@@ -3,6 +3,7 @@
3
3
  module Otoroshi
4
4
  # This module is designed to be included in a class. This will provide
5
5
  # the "property" ({Sanctuary::ClassMethods.property}) method for defining class properties.
6
+ #
6
7
  # @example
7
8
  # class Importer
8
9
  # include Otoroshi::Sanctuary
@@ -23,12 +24,15 @@ module Otoroshi
23
24
  # Class methods extended for the base class
24
25
  module ClassMethods
25
26
  # Adds a new "property" to the class
27
+ #
26
28
  # @param name [Symbol] the property name
27
29
  # @param type [Class] the expected value type
28
30
  # @param validate [Proc] a lambda processing the value and returning true or false
29
31
  # @param allow_nil [true, false] allow nil as a value
30
32
  # @param default [Object] default value if not set on initialization
33
+ #
31
34
  # @return [void]
35
+ #
32
36
  # @example
33
37
  # property name, type: String, validate: ->(v) { v.length > 3 }, allow_nil: true
34
38
  # @example
@@ -43,7 +47,9 @@ module Otoroshi
43
47
  end
44
48
 
45
49
  # Returns the class properties
50
+ #
46
51
  # @return [Hash]
52
+ #
47
53
  # @note this method will be updated by {add_to_properties}
48
54
  def properties
49
55
  {}
@@ -52,6 +58,7 @@ module Otoroshi
52
58
  private
53
59
 
54
60
  # Updates {properties} to add new property to the returned ones
61
+ #
55
62
  # @return [void]
56
63
  def add_to_properties(name, allow_nil, default)
57
64
  current_state = properties
@@ -60,10 +67,13 @@ module Otoroshi
60
67
  end
61
68
 
62
69
  # Defines a private method that raises an error if type is not respected
70
+ #
63
71
  # @param name [Symbol] the property name
64
72
  # @param type [Class] the type to test against
65
73
  # @param allow_nil [true, false] allow nil as a value
74
+ #
66
75
  # @return [void]
76
+ #
67
77
  # @example
68
78
  # define_validate_type!(score, Integer, false) => def validate_score_type!(value) ...
69
79
  # @example Generated method
@@ -85,8 +95,11 @@ module Otoroshi
85
95
  end
86
96
 
87
97
  # Defines a lambda to be call to validate that value matches the type
98
+ #
88
99
  # @param type [Class] the type to test against
100
+ #
89
101
  # @return [Proc] the lambda to use in order to test the value matches the type
102
+ #
90
103
  # @example
91
104
  # type_validation(Integer) #=> ->(v) { v.is_a? Integer }
92
105
  # @example
@@ -100,10 +113,13 @@ module Otoroshi
100
113
  end
101
114
 
102
115
  # Defines a private method that raises an error if validate block returns false
116
+ #
103
117
  # @param name [Symbol] the property name
104
118
  # @param validate [Proc] a lambda processing the value and returning true or false
105
119
  # @param allow_nil [true, false] allow nil as a value
120
+ #
106
121
  # @return [void]
122
+ #
107
123
  # @example
108
124
  # define_validate_lambda!("score", ->(v) { v >= 0 }, false) #=> def validate_score_lambda!(value) ...
109
125
  # @example Generated instance method
@@ -124,8 +140,11 @@ module Otoroshi
124
140
  end
125
141
 
126
142
  # Defines a getter method for the property
143
+ #
127
144
  # @param name [Symbol] the property name
145
+ #
128
146
  # @return [void]
147
+ #
129
148
  # @example
130
149
  # define_getter(:score) #=> def score ...
131
150
  # @example Generated instance method
@@ -137,8 +156,11 @@ module Otoroshi
137
156
  end
138
157
 
139
158
  # Defines a setter method for the property
159
+ #
140
160
  # @param name [Symbol] the property name
161
+ #
141
162
  # @return [void]
163
+ #
142
164
  # @example
143
165
  # define_getter(:score) #=> def score=(value) ...
144
166
  # @example Generated instance method
@@ -156,8 +178,11 @@ module Otoroshi
156
178
  end
157
179
 
158
180
  # Redefines initialize method
181
+ #
159
182
  # @return [void]
183
+ #
160
184
  # @note method is defined with `class_eval`
185
+ #
161
186
  # @example Generated method
162
187
  # def initialize(foo:, bar: 0)
163
188
  # self.foo = foo
@@ -172,7 +197,9 @@ module Otoroshi
172
197
  end
173
198
 
174
199
  # Defines initialize method parameters
200
+ #
175
201
  # @return [String]
202
+ #
176
203
  # @example Given properties { foo: { allow_nil: false, default: nil }, { allow_nil: true, default: 0 } }
177
204
  # redefine_initialize #=> "foo:, bar: 0"
178
205
  def initialize_parameters
@@ -185,8 +212,11 @@ module Otoroshi
185
212
  end
186
213
 
187
214
  # Defines the default value of a parameter depending on options
215
+ #
188
216
  # @param options [Hash]
217
+ #
189
218
  # @return [String]
219
+ #
190
220
  # @example when nil is allowed and default is set
191
221
  # default_parameter_for(true, 0) #=> " 0"
192
222
  # @example when nil is allowed and default is not set
@@ -200,7 +230,9 @@ module Otoroshi
200
230
  end
201
231
 
202
232
  # Defines initialize method body
233
+ #
203
234
  # @return [String]
235
+ #
204
236
  # @example Given properties { foo: { allow_nil: false, default: nil }, { allow_nil: true, default: 0 } }
205
237
  # initialize_body #=> "self.foo = foo\nself.bar = bar"
206
238
  def initialize_body
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.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edouard Piron