envee 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f94f269e8d206155b0b450605a6d6c8583b691e
4
- data.tar.gz: 7c00b33fbdabc979917bff9252082061953b4b66
3
+ metadata.gz: 824832af193657ff86be9e8cf81cdbd88bbe7083
4
+ data.tar.gz: 5acc339405e11452663c18095845538157a69bae
5
5
  SHA512:
6
- metadata.gz: 40bb0f11403e0a96e5ad0fcdbb3c7d528b849854c202ffa0d6402635e5dc69dbd833acaec456fa247b2f8a4c57146b33d896e51b3291df7a6a66cd1830b8731b
7
- data.tar.gz: 283fb912b6021af77e8511d5cf5cc5ddd9261fc71d0e1e9564830c222d1d241dd94958dc187560a16934c95f0f15eb1bb313206268e46b4865e6849761d29faf
6
+ metadata.gz: 01aebb8fe0d719957bc87e3a4045b7cf54d5ab3ab94d95b3261321aeb7a6eb6f84b5d6dcd4ff86d4219b4eecdad4fa8ffdabaa04baf1d6c361027a52f11bb562
7
+ data.tar.gz: 80f9ae958f80e6218f19a62f2dde7db177f3dc23beccb165a589a13d62d515ffa6632e8d2e8176533a02d33e893b3746e85b215ac6a975e854f8b37e907be04e
@@ -0,0 +1,467 @@
1
+ # Common configuration.
2
+ AllCops:
3
+ # Include gemspec and Rakefile
4
+ Include:
5
+ - '**/*.gemspec'
6
+ - '**/Rakefile'
7
+ - '**/*.rake'
8
+ - '**/Gemfile'
9
+ Exclude:
10
+ - 'vendor/**'
11
+ RunRailsCops: false
12
+
13
+ # Indent private/protected/public as deep as method definitions
14
+ AccessModifierIndentation:
15
+ EnforcedStyle: outdent
16
+ SupportedStyles:
17
+ - outdent
18
+ - indent
19
+
20
+ # Indentation of `when`.
21
+ CaseIndentation:
22
+ IndentWhenRelativeTo: end
23
+ SupportedStyles:
24
+ - case
25
+ - end
26
+ IndentOneStep: false
27
+
28
+ ClassLength:
29
+ CountComments: false # count full line comments?
30
+ Max: 200
31
+
32
+ # Align ends correctly.
33
+ EndAlignment:
34
+ # The value `keyword` means that `end` should be aligned with the matching
35
+ # keyword (if, while, etc.).
36
+ # The value `variable` means that in assignments, `end` should be aligned
37
+ # with the start of the variable on the left hand side of `=`. In all other
38
+ # situations, `end` should still be aligned with the keyword.
39
+ AlignWith: variable
40
+ SupportedStyles:
41
+ - keyword
42
+ - variable
43
+
44
+ # Built-in global variables are allowed by default.
45
+ GlobalVars:
46
+ AllowedVariables: ['$1', '$2', '$3', '$4', '$5', '$6']
47
+
48
+ LineLength:
49
+ Max: 120
50
+
51
+ MethodLength:
52
+ CountComments: false # count full line comments?
53
+ Max: 20
54
+
55
+ NumericLiterals:
56
+ MinDigits: 10
57
+
58
+ SignalException:
59
+ EnforcedStyle: only_raise
60
+ SupportedStyles:
61
+ - only_raise
62
+ - only_fail
63
+ - semantic
64
+
65
+ SpaceBeforeBlockBraces:
66
+ EnforcedStyle: no_space
67
+ SupportedStyles:
68
+ - space
69
+ - no_space
70
+
71
+ SpaceInsideBlockBraces:
72
+ EnforcedStyle: no_space
73
+ SupportedStyles:
74
+ - space
75
+ - no_space
76
+ # Valid values are: space, no_space
77
+ EnforcedStyleForEmptyBraces: no_space
78
+ # Space between { and |. Overrides EnforcedStyle if there is a conflict.
79
+ SpaceBeforeBlockParameters: false
80
+
81
+ SpaceInsideHashLiteralBraces:
82
+ EnforcedStyle: no_space
83
+ EnforcedStyleForEmptyBraces: no_space
84
+ SupportedStyles:
85
+ - space
86
+ - no_space
87
+
88
+ # Checks whether the source file has a utf-8 encoding comment or not
89
+ Encoding:
90
+ EnforcedStyle: when_needed
91
+ SupportedStyles:
92
+ - when_needed
93
+ - always
94
+
95
+ WordArray:
96
+ MinSize: 0
97
+
98
+ ##########################################################################
99
+ ####################### DEFAULTS FROM RUBOCOP ############################
100
+ ##########################################################################
101
+
102
+ # Align the elements of a hash literal if they span more than one line.
103
+ AlignHash:
104
+ # Alignment of entries using hash rocket as separator. Valid values are:
105
+ #
106
+ # key - left alignment of keys
107
+ # 'a' => 2
108
+ # 'bb' => 3
109
+ # separator - alignment of hash rockets, keys are right aligned
110
+ # 'a' => 2
111
+ # 'bb' => 3
112
+ # table - left alignment of keys, hash rockets, and values
113
+ # 'a' => 2
114
+ # 'bb' => 3
115
+ EnforcedHashRocketStyle: key
116
+ # Alignment of entries using colon as separator. Valid values are:
117
+ #
118
+ # key - left alignment of keys
119
+ # a: 0
120
+ # bb: 1
121
+ # separator - alignment of colons, keys are right aligned
122
+ # a: 0
123
+ # bb: 1
124
+ # table - left alignment of keys and values
125
+ # a: 0
126
+ # bb: 1
127
+ EnforcedColonStyle: key
128
+ # Select whether hashes that are the last argument in a method call should be
129
+ # inspected? Valid values are:
130
+ #
131
+ # always_inspect - Inspect both implicit and explicit hashes.
132
+ # Registers and offence for:
133
+ # function(a: 1,
134
+ # b: 2)
135
+ # Registers an offence for:
136
+ # function({a: 1,
137
+ # b: 2})
138
+ # always_ignore - Ignore both implicit and explicit hashes.
139
+ # Accepts:
140
+ # function(a: 1,
141
+ # b: 2)
142
+ # Accepts:
143
+ # function({a: 1,
144
+ # b: 2})
145
+ # ignore_implicit - Ingore only implicit hashes.
146
+ # Accepts:
147
+ # function(a: 1,
148
+ # b: 2)
149
+ # Registers an offence for:
150
+ # function({a: 1,
151
+ # b: 2})
152
+ # ignore_explicit - Ingore only explicit hashes.
153
+ # Accepts:
154
+ # function({a: 1,
155
+ # b: 2})
156
+ # Registers an offence for:
157
+ # function(a: 1,
158
+ # b: 2)
159
+ EnforcedLastArgumentHashStyle: always_inspect
160
+ SupportedLastArgumentHashStyles:
161
+ - always_inspect
162
+ - always_ignore
163
+ - ignore_implicit
164
+ - ignore_explicit
165
+
166
+ AlignParameters:
167
+ # Alignment of parameters in multi-line method calls.
168
+ #
169
+ # The `with_first_parameter` style aligns the following lines along the same column
170
+ # as the first parameter.
171
+ #
172
+ # method_call(a,
173
+ # b)
174
+ #
175
+ # The `with_fixed_indentation` style alignes the following lines with one
176
+ # level of indenation relative to the start of the line with the method call.
177
+ #
178
+ # method_call(a,
179
+ # b)
180
+ EnforcedStyle: with_first_parameter
181
+ SupportedStyles:
182
+ - with_first_parameter
183
+ - with_fixed_indentation
184
+
185
+ # Allow safe assignment in conditions.
186
+ AssignmentInCondition:
187
+ AllowSafeAssignment: true
188
+
189
+ BlockNesting:
190
+ Max: 3
191
+
192
+ BracesAroundHashParameters:
193
+ EnforcedStyle: no_braces
194
+ SupportedStyles:
195
+ - braces
196
+ - no_braces
197
+
198
+ ClassAndModuleChildren:
199
+ # Checks the style of children definitions at classes and modules.
200
+ #
201
+ # Basically there are two different styles:
202
+ #
203
+ # `nested` - have each child on a separat line
204
+ # class Foo
205
+ # class Bar
206
+ # end
207
+ # end
208
+ #
209
+ # `compact` - combine definitions as much as possible
210
+ # class Foo::Bar
211
+ # end
212
+ #
213
+ # The compact style is only forced, for classes / modules with one child.
214
+ EnforcedStyle: nested
215
+ SupportedStyles:
216
+ - nested
217
+ - compact
218
+
219
+ # Align with the style guide.
220
+ CollectionMethods:
221
+ # Mapping from undesired method to desired_method
222
+ # e.g. to use `detect` over `find`:
223
+ #
224
+ # CollectionMethods:
225
+ # PreferredMethods:
226
+ # find: detect
227
+ PreferredMethods:
228
+ collect: 'map'
229
+ collect!: 'map!'
230
+ inject: 'reduce'
231
+ detect: 'find'
232
+ find_all: 'select'
233
+
234
+ # Checks formatting of special comments
235
+ CommentAnnotation:
236
+ Keywords:
237
+ - TODO
238
+ - FIXME
239
+ - OPTIMIZE
240
+ - HACK
241
+ - REVIEW
242
+
243
+ # Avoid complex methods.
244
+ CyclomaticComplexity:
245
+ Max: 6
246
+
247
+ # Multi-line method chaining should be done with leading dots.
248
+ DotPosition:
249
+ EnforcedStyle: leading
250
+ SupportedStyles:
251
+ - leading
252
+ - trailing
253
+
254
+ # Use empty lines between defs.
255
+ EmptyLineBetweenDefs:
256
+ # If true, this parameter means that single line method definitions don't
257
+ # need an empty line between them.
258
+ AllowAdjacentOneLineDefs: false
259
+
260
+ FileName:
261
+ Exclude:
262
+ - Rakefile
263
+ - Gemfile
264
+ - Capfile
265
+
266
+ # Checks use of for or each in multiline loops.
267
+ For:
268
+ EnforcedStyle: each
269
+ SupportedStyles:
270
+ - for
271
+ - each
272
+
273
+ # Enforce the method used for string formatting.
274
+ FormatString:
275
+ EnforcedStyle: format
276
+ SupportedStyles:
277
+ - format
278
+ - sprintf
279
+ - percent
280
+
281
+ HashSyntax:
282
+ EnforcedStyle: ruby19
283
+ SupportedStyles:
284
+ - ruby19
285
+ - hash_rockets
286
+
287
+ IfUnlessModifier:
288
+ MaxLineLength: 79
289
+
290
+ # Checks the indentation of the first key in a hash literal.
291
+ IndentHash:
292
+ # The value `special_inside_parentheses` means that hash literals with braces
293
+ # that have their opening brace on the same line as a surrounding opening
294
+ # round parenthesis, shall have their first key indented relative to the
295
+ # first position inside the parenthesis.
296
+ # The value `consistent` means that the indentation of the first key shall
297
+ # always be relative to the first position of the line where the opening
298
+ # brace is.
299
+ EnforcedStyle: special_inside_parentheses
300
+ SupportedStyles:
301
+ - special_inside_parentheses
302
+ - consistent
303
+
304
+ LambdaCall:
305
+ EnforcedStyle: call
306
+ SupportedStyles:
307
+ - call
308
+ - braces
309
+
310
+ MethodDefParentheses:
311
+ EnforcedStyle: require_parentheses
312
+ SupportedStyles:
313
+ - require_parentheses
314
+ - require_no_parentheses
315
+
316
+ MethodLength:
317
+ CountComments: false # count full line comments?
318
+ Max: 10
319
+
320
+ MethodName:
321
+ EnforcedStyle: snake_case
322
+ SupportedStyles:
323
+ - snake_case
324
+ - camelCase
325
+
326
+ ParameterLists:
327
+ Max: 5
328
+ CountKeywordArgs: true
329
+
330
+ # Allow safe assignment in conditions.
331
+ ParenthesesAroundCondition:
332
+ AllowSafeAssignment: true
333
+
334
+ PercentLiteralDelimiters:
335
+ PreferredDelimiters:
336
+ '%': ()
337
+ '%i': ()
338
+ '%q': ()
339
+ '%Q': ()
340
+ '%r': '{}'
341
+ '%s': ()
342
+ '%w': ()
343
+ '%W': ()
344
+ '%x': ()
345
+
346
+ PredicateName:
347
+ NamePrefixBlacklist:
348
+ - is_
349
+ - has_
350
+ - have_
351
+
352
+ RaiseArgs:
353
+ EnforcedStyle: exploded
354
+ SupportedStyles:
355
+ - compact # raise Exception.new(msg)
356
+ - exploded # raise Exception, msg
357
+
358
+
359
+ RedundantReturn:
360
+ # When true allows code like `return x, y`.
361
+ AllowMultipleReturnValues: false
362
+
363
+ Semicolon:
364
+ # Allow ; to separate several expressions on the same line.
365
+ AllowAsExpressionSeparator: false
366
+
367
+ SingleLineBlockParams:
368
+ Methods:
369
+ - reduce:
370
+ - a
371
+ - e
372
+ - inject:
373
+ - a
374
+ - e
375
+
376
+ SingleLineMethods:
377
+ AllowIfMethodIsEmpty: true
378
+
379
+ StringLiterals:
380
+ EnforcedStyle: single_quotes
381
+ SupportedStyles:
382
+ - single_quotes
383
+ - double_quotes
384
+
385
+ SpaceAroundEqualsInParameterDefault:
386
+ EnforcedStyle: space
387
+ SupportedStyles:
388
+ - space
389
+ - no_space
390
+
391
+ TrailingComma:
392
+ EnforcedStyleForMultiline: no_comma
393
+ SupportedStyles:
394
+ - comma
395
+ - no_comma
396
+
397
+ # TrivialAccessors doesn't require exact name matches and doesn't allow
398
+ # predicated methods by default.
399
+ TrivialAccessors:
400
+ ExactNameMatch: false
401
+ AllowPredicates: false
402
+ # Allows trivial writers that don't end in an equal sign. e.g.
403
+ #
404
+ # def on_exception(action)
405
+ # @on_exception=action
406
+ # end
407
+ # on_exception :restart
408
+ #
409
+ # Commonly used in DSLs
410
+ AllowDSLWriters: false
411
+ Whitelist:
412
+ - to_ary
413
+ - to_a
414
+ - to_c
415
+ - to_enum
416
+ - to_h
417
+ - to_hash
418
+ - to_i
419
+ - to_int
420
+ - to_io
421
+ - to_open
422
+ - to_path
423
+ - to_proc
424
+ - to_r
425
+ - to_regexp
426
+ - to_str
427
+ - to_s
428
+ - to_sym
429
+
430
+ VariableName:
431
+ EnforcedStyle: snake_case
432
+ SupportedStyles:
433
+ - snake_case
434
+ - camelCase
435
+
436
+ WhileUntilModifier:
437
+ MaxLineLength: 79
438
+
439
+ ##################### Rails ##################################
440
+
441
+ ActionFilter:
442
+ EnforcedStyle: action
443
+ SupportedStyles:
444
+ - action
445
+ - filter
446
+ Include:
447
+ - app/controllers/*.rb
448
+
449
+ DefaultScope:
450
+ Include:
451
+ - app/models/*.rb
452
+
453
+ HasAndBelongsToMany:
454
+ Include:
455
+ - app/models/*.rb
456
+
457
+ ReadWriteAttribute:
458
+ Include:
459
+ - app/models/*.rb
460
+
461
+ ScopeArgs:
462
+ Include:
463
+ - app/models/*.rb
464
+
465
+ Validation:
466
+ Include:
467
+ - app/models/*.rb
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
7
-
6
+ task default: :spec
@@ -4,20 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'envee/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "envee"
7
+ spec.name = 'envee'
8
8
  spec.version = Envee::VERSION
9
- spec.authors = ["Allen Madsen"]
10
- spec.email = ["blatyo@gmail.com"]
9
+ spec.authors = ['Allen Madsen']
10
+ spec.email = ['blatyo@gmail.com']
11
11
  spec.summary = 'Provides casting wrappers around fetch for environment variables.'
12
- spec.homepage = ""
13
- spec.license = "MIT"
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.executables = spec.files.grep(%r{^bin/}){|f| File.basename(f)}
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.7"
21
- spec.add_development_dependency "rake", "~> 10.0"
22
- spec.add_development_dependency "rspec"
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec'
23
23
  end
@@ -1,7 +1,9 @@
1
1
  require 'envee/version'
2
2
  require 'time'
3
3
 
4
+ # Adds casting fetchers and validation for values filled with a placeholder.
4
5
  module Envee
6
+ # Error thrown by validate when there are missing keys
5
7
  class MissingValuesError < StandardError
6
8
  def initialize(missing_keys)
7
9
  super(
@@ -15,14 +17,22 @@ module Envee
15
17
  Integer(fetch(*args, &block))
16
18
  end
17
19
 
20
+ def fl(*args, &block)
21
+ Float(fetch(*args, &block))
22
+ end
23
+
18
24
  def str(*args, &block)
19
25
  String(fetch(*args, &block))
20
26
  end
21
27
 
28
+ def sym(*args, &block)
29
+ String(fetch(*args, &block)).to_sym
30
+ end
31
+
22
32
  def bool(*args, &block)
23
33
  value = fetch(*args, &block)
24
34
 
25
- value && value !~ /^(0|no|false|off|)$/i
35
+ value && value !~ /\A(0|no|false|off|nil|null|)\z/i
26
36
  end
27
37
 
28
38
  def time(*args, &block)
@@ -38,9 +48,9 @@ module Envee
38
48
  end
39
49
 
40
50
  def validate!(options)
41
- missing = options[:missing_value]
42
- missing_keys = select{|k, v| v.include?(missing)}.map(&:first)
43
- raise MissingValuesError.new(missing_keys) unless missing_keys.empty?
51
+ missing = options[:placeholder] || 'CHANGEME'
52
+ missing_keys = select{|_k, v| v.include?(missing)}.map(&:first)
53
+ raise MissingValuesError, missing_keys unless missing_keys.empty?
44
54
  end
45
55
  end
46
56
 
@@ -1,3 +1,4 @@
1
+ # Version
1
2
  module Envee
2
- VERSION = "0.0.1"
3
+ VERSION = '0.0.2'
3
4
  end
@@ -41,6 +41,40 @@ describe Envee do
41
41
  end
42
42
  end
43
43
 
44
+ describe '#fl' do
45
+ context 'when requesting a value in env without default' do
46
+ it 'returns env value casted as float' do
47
+ env['NUM'] = '1.0'
48
+ expect(env.fl('NUM')).to eq(1.0)
49
+ end
50
+ end
51
+
52
+ context 'when requesting a value not in env with a default value' do
53
+ it 'returns the default value casted as float' do
54
+ expect(env.fl('NUM', '2.1')).to eq(2.1)
55
+ end
56
+ end
57
+
58
+ context 'when requesting a value not in env with a default block' do
59
+ it 'returns the default block value casted as float' do
60
+ expect(env.fl('NUM'){'2.1'}).to eq(2.1)
61
+ end
62
+ end
63
+
64
+ context 'when requesting a value not in env with no default' do
65
+ it 'raises an KeyError' do
66
+ expect{env.fl('NUM')}.to raise_error(KeyError)
67
+ end
68
+ end
69
+
70
+ context 'when requesting a value in env that cannot be casted to float' do
71
+ it 'raises an ArgumentError' do
72
+ env['NUM'] = 'a'
73
+ expect{env.fl('NUM')}.to raise_error(ArgumentError)
74
+ end
75
+ end
76
+ end
77
+
44
78
  describe '#str' do
45
79
  context 'when requesting a value in env without default' do
46
80
  it 'returns env value casted as string' do
@@ -68,6 +102,33 @@ describe Envee do
68
102
  end
69
103
  end
70
104
 
105
+ describe '#sym' do
106
+ context 'when requesting a value in env without default' do
107
+ it 'returns env value casted as symbol' do
108
+ env['NUM'] = '1'
109
+ expect(env.sym('NUM')).to eq(:'1')
110
+ end
111
+ end
112
+
113
+ context 'when requesting a value not in env with a default value' do
114
+ it 'returns the default value casted as symbol' do
115
+ expect(env.sym('NUM', 2)).to eq(:'2')
116
+ end
117
+ end
118
+
119
+ context 'when requesting a value not in env with a default block' do
120
+ it 'returns the default block value casted as symbol' do
121
+ expect(env.sym('NUM'){2}).to eq(:'2')
122
+ end
123
+ end
124
+
125
+ context 'when requesting a value not in env with no default' do
126
+ it 'raises an KeyError' do
127
+ expect{env.sym('NUM')}.to raise_error(KeyError)
128
+ end
129
+ end
130
+ end
131
+
71
132
  describe '#bool' do
72
133
  context 'when requesting a value in env without default' do
73
134
  it 'returns env value casted as truthy' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envee
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
  - Allen Madsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".rspec"
64
+ - ".rubocop.yml"
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
91
  version: '0'
91
92
  requirements: []
92
93
  rubyforge_project:
93
- rubygems_version: 2.4.3
94
+ rubygems_version: 2.4.5.1
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Provides casting wrappers around fetch for environment variables.