gemsupport 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65900af3e375447e020ac05a186b02598ddce623
4
+ data.tar.gz: b09b3c26b86d0c7be0a38129b978692c0ab3a6d3
5
+ SHA512:
6
+ metadata.gz: dbf79859c0b17c50703ff891c456a74cb980cb149b9f7207994a40ab8eafb6596c57955e716ed7528ef5e1d500eaf1db91c44e17c6de18c2145a995752083d94
7
+ data.tar.gz: 820eb6e1f0cd29a1ac21bfc85cbf788bb2e69d4cae10365010fa5ebf36639f73c5168fa40d889427541771cdf70b8766cd8fc91a315231ba4658dc0eb26edae8
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,491 @@
1
+ # https://github.com/bbatsov/rubocop/tree/master/config
2
+ # => default.yml
3
+ # => disabled.yml
4
+ # => enabled.yml
5
+
6
+ # This is the default configuration file. Enabling and disabling is configured
7
+ # in separate files. This file adds all other parameters apart from Enabled.
8
+
9
+ # inherit_from:
10
+ # - enabled.yml
11
+ # - disabled.yml
12
+
13
+ # Common configuration.
14
+ AllCops:
15
+ # Include gemspec and Rakefile
16
+ Include:
17
+ - '**/*.gemspec'
18
+ - '**/Rakefile'
19
+ - 'config/routes.rb'
20
+ Exclude:
21
+ - 'vendor/**'
22
+ - 'db/**'
23
+ - 'config/**'
24
+ - 'script/**'
25
+ - 'bin/**'
26
+ - 'lib/docker/testing/container/template.rb'
27
+ # By default, the rails cops are not run. Override in project or home
28
+ # directory .rubocop.yml files, or by giving the -R/--rails option.
29
+ RunRailsCops: true
30
+
31
+ # Indent private/protected/public as deep as method definitions
32
+ AccessModifierIndentation:
33
+ EnforcedStyle: indent
34
+ SupportedStyles:
35
+ - outdent
36
+ - indent
37
+
38
+ # Align the elements of a hash literal if they span more than one line.
39
+ AlignHash:
40
+ # Alignment of entries using hash rocket as separator. Valid values are:
41
+ #
42
+ # key - left alignment of keys
43
+ # 'a' => 2
44
+ # 'bb' => 3
45
+ # separator - alignment of hash rockets, keys are right aligned
46
+ # 'a' => 2
47
+ # 'bb' => 3
48
+ # table - left alignment of keys, hash rockets, and values
49
+ # 'a' => 2
50
+ # 'bb' => 3
51
+ EnforcedHashRocketStyle: key
52
+ # Alignment of entries using colon as separator. Valid values are:
53
+ #
54
+ # key - left alignment of keys
55
+ # a: 0
56
+ # bb: 1
57
+ # separator - alignment of colons, keys are right aligned
58
+ # a: 0
59
+ # bb: 1
60
+ # table - left alignment of keys and values
61
+ # a: 0
62
+ # bb: 1
63
+ EnforcedColonStyle: key
64
+ # Select whether hashes that are the last argument in a method call should be
65
+ # inspected? Valid values are:
66
+ #
67
+ # always_inspect - Inspect both implicit and explicit hashes.
68
+ # Registers and offence for:
69
+ # function(a: 1,
70
+ # b: 2)
71
+ # Registers an offence for:
72
+ # function({a: 1,
73
+ # b: 2})
74
+ # always_ignore - Ignore both implicit and explicit hashes.
75
+ # Accepts:
76
+ # function(a: 1,
77
+ # b: 2)
78
+ # Accepts:
79
+ # function({a: 1,
80
+ # b: 2})
81
+ # ignore_implicit - Ingore only implicit hashes.
82
+ # Accepts:
83
+ # function(a: 1,
84
+ # b: 2)
85
+ # Registers an offence for:
86
+ # function({a: 1,
87
+ # b: 2})
88
+ # ignore_explicit - Ingore only explicit hashes.
89
+ # Accepts:
90
+ # function({a: 1,
91
+ # b: 2})
92
+ # Registers an offence for:
93
+ # function(a: 1,
94
+ # b: 2)
95
+ EnforcedLastArgumentHashStyle: always_inspect
96
+ SupportedLastArgumentHashStyles:
97
+ - always_inspect
98
+ - always_ignore
99
+ - ignore_implicit
100
+ - ignore_explicit
101
+
102
+ AlignParameters:
103
+ # Alignment of parameters in multi-line method calls.
104
+ #
105
+ # The `with_first_parameter` style aligns the following lines along the same column
106
+ # as the first parameter.
107
+ #
108
+ # method_call(a,
109
+ # b)
110
+ #
111
+ # The `with_fixed_indentation` style alignes the following lines with one
112
+ # level of indenation relative to the start of the line with the method call.
113
+ #
114
+ # method_call(a,
115
+ # b)
116
+ EnforcedStyle: with_first_parameter
117
+ SupportedStyles:
118
+ - with_first_parameter
119
+ - with_fixed_indentation
120
+
121
+ # Allow safe assignment in conditions.
122
+ AssignmentInCondition:
123
+ AllowSafeAssignment: true
124
+
125
+ AmbiguousOperator:
126
+ Enabled: false
127
+
128
+ BlockNesting:
129
+ Max: 3
130
+
131
+ BracesAroundHashParameters:
132
+ EnforcedStyle: no_braces
133
+ SupportedStyles:
134
+ - braces
135
+ - no_braces
136
+
137
+ # Indentation of `when`.
138
+ CaseIndentation:
139
+ IndentWhenRelativeTo: case
140
+ SupportedStyles:
141
+ - case
142
+ - end
143
+ IndentOneStep: false
144
+
145
+ ClassAndModuleChildren:
146
+ # Checks the style of children definitions at classes and modules.
147
+ #
148
+ # Basically there are two different styles:
149
+ #
150
+ # `nested` - have each child on a separat line
151
+ # class Foo
152
+ # class Bar
153
+ # end
154
+ # end
155
+ #
156
+ # `compact` - combine definitions as much as possible
157
+ # class Foo::Bar
158
+ # end
159
+ #
160
+ # The compact style is only forced, for classes / modules with one child.
161
+ EnforcedStyle: nested
162
+ SupportedStyles:
163
+ - nested
164
+ - compact
165
+
166
+ ClassLength:
167
+ CountComments: false # count full line comments?
168
+ Max: 140
169
+
170
+ # Align with the style guide.
171
+ CollectionMethods:
172
+ PreferredMethods:
173
+ collect: 'map'
174
+ collect!: 'map!'
175
+ inject: 'reduce'
176
+ detect: 'find'
177
+ find_all: 'select'
178
+
179
+ # Checks formatting of special comments
180
+ CommentAnnotation:
181
+ Keywords:
182
+ - TODO
183
+ - FIXME
184
+ - OPTIMIZE
185
+ - HACK
186
+ - REVIEW
187
+
188
+ # Avoid complex methods.
189
+ CyclomaticComplexity:
190
+ Max: 6
191
+
192
+ # Multi-line method chaining should be done with leading dots.
193
+ DotPosition:
194
+ EnforcedStyle: leading
195
+ SupportedStyles:
196
+ - leading
197
+ - trailing
198
+
199
+ # Use empty lines between defs.
200
+ EmptyLineBetweenDefs:
201
+ # If true, this parameter means that single line method definitions don't
202
+ # need an empty line between them.
203
+ AllowAdjacentOneLineDefs: false
204
+
205
+ # Align ends correctly.
206
+ EndAlignment:
207
+ # The value `keyword` means that `end` should be aligned with the matching
208
+ # keyword (if, while, etc.).
209
+ # The value `variable` means that in assignments, `end` should be aligned
210
+ # with the start of the variable on the left hand side of `=`. In all other
211
+ # situations, `end` should still be aligned with the keyword.
212
+ AlignWith: keyword
213
+ SupportedStyles:
214
+ - keyword
215
+ - variable
216
+
217
+ FileName:
218
+ Exclude:
219
+ - Rakefile
220
+ - Gemfile
221
+ - Capfile
222
+
223
+ # Checks use of for or each in multiline loops.
224
+ For:
225
+ EnforcedStyle: each
226
+ SupportedStyles:
227
+ - for
228
+ - each
229
+
230
+ # Enforce the method used for string formatting.
231
+ FormatString:
232
+ EnforcedStyle: format
233
+ SupportedStyles:
234
+ - format
235
+ - sprintf
236
+ - percent
237
+
238
+ # Built-in global variables are allowed by default.
239
+ GlobalVars:
240
+ AllowedVariables: []
241
+
242
+ HashSyntax:
243
+ EnforcedStyle: ruby19
244
+ SupportedStyles:
245
+ - ruby19
246
+ - hash_rockets
247
+
248
+ IfUnlessModifier:
249
+ MaxLineLength: 99
250
+
251
+ # Checks the indentation of the first key in a hash literal.
252
+ IndentHash:
253
+ # The value `special_inside_parentheses` means that hash literals with braces
254
+ # that have their opening brace on the same line as a surrounding opening
255
+ # round parenthesis, shall have their first key indented relative to the
256
+ # first position inside the parenthesis.
257
+ # The value `consistent` means that the indentation of the first key shall
258
+ # always be relative to the first position of the line where the opening
259
+ # brace is.
260
+ EnforcedStyle: special_inside_parentheses
261
+ SupportedStyles:
262
+ - special_inside_parentheses
263
+ - consistent
264
+
265
+ LambdaCall:
266
+ EnforcedStyle: call
267
+ SupportedStyles:
268
+ - call
269
+ - braces
270
+
271
+ LineLength:
272
+ Max: 99
273
+
274
+ MethodDefParentheses:
275
+ EnforcedStyle: require_parentheses
276
+ SupportedStyles:
277
+ - require_parentheses
278
+ - require_no_parentheses
279
+
280
+ MethodLength:
281
+ CountComments: false # count full line comments?
282
+ Max: 16
283
+
284
+ MethodName:
285
+ EnforcedStyle: snake_case
286
+ SupportedStyles:
287
+ - snake_case
288
+ - camelCase
289
+
290
+ NumericLiterals:
291
+ MinDigits: 5
292
+
293
+ ParameterLists:
294
+ Max: 5
295
+ CountKeywordArgs: true
296
+
297
+ # Allow safe assignment in conditions.
298
+ ParenthesesAroundCondition:
299
+ AllowSafeAssignment: true
300
+
301
+ PercentLiteralDelimiters:
302
+ PreferredDelimiters:
303
+ '%': ()
304
+ '%i': ()
305
+ '%q': ()
306
+ '%Q': ()
307
+ '%r': '{}'
308
+ '%s': ()
309
+ '%w': ()
310
+ '%W': ()
311
+ '%x': ()
312
+
313
+ PredicateName:
314
+ NamePrefixBlacklist:
315
+ - is_
316
+ - has_
317
+ - have_
318
+
319
+ RaiseArgs:
320
+ EnforcedStyle: exploded
321
+ SupportedStyles:
322
+ - compact # raise Exception.new(msg)
323
+ - exploded # raise Exception, msg
324
+
325
+
326
+ RedundantReturn:
327
+ # When true allows code like `return x, y`.
328
+ AllowMultipleReturnValues: false
329
+
330
+ RedundantSelf:
331
+ Description: "Don't use self where it's not needed."
332
+ Enabled: false
333
+
334
+ RegexpLiteral:
335
+ # The maximum number of (escaped) slashes that a slash-delimited regexp is
336
+ # allowed to have. If there are more slashes, a %r regexp shall be used.
337
+ MaxSlashes: 1
338
+
339
+ Semicolon:
340
+ # Allow ; to separate several expressions on the same line.
341
+ AllowAsExpressionSeparator: false
342
+
343
+ SignalException:
344
+ EnforcedStyle: semantic
345
+ SupportedStyles:
346
+ - only_raise
347
+ - only_fail
348
+ - semantic
349
+
350
+
351
+ SingleLineBlockParams:
352
+ Methods:
353
+ - reduce:
354
+ - a
355
+ - e
356
+ - inject:
357
+ - a
358
+ - e
359
+
360
+ SingleLineMethods:
361
+ AllowIfMethodIsEmpty: true
362
+
363
+ StringLiterals:
364
+ EnforcedStyle: single_quotes
365
+ SupportedStyles:
366
+ - single_quotes
367
+ - double_quotes
368
+
369
+ SpaceAroundEqualsInParameterDefault:
370
+ EnforcedStyle: space
371
+ SupportedStyles:
372
+ - space
373
+ - no_space
374
+
375
+ SpaceBeforeBlockBraces:
376
+ EnforcedStyle: space
377
+ SupportedStyles:
378
+ - space
379
+ - no_space
380
+
381
+ SpaceInsideBlockBraces:
382
+ EnforcedStyle: space
383
+ SupportedStyles:
384
+ - space
385
+ - no_space
386
+ # Valid values are: space, no_space
387
+ EnforcedStyleForEmptyBraces: no_space
388
+ # Space between { and |. Overrides EnforcedStyle if there is a conflict.
389
+ SpaceBeforeBlockParameters: true
390
+
391
+ SpaceInsideHashLiteralBraces:
392
+ EnforcedStyle: space
393
+ EnforcedStyleForEmptyBraces: no_space
394
+ SupportedStyles:
395
+ - space
396
+ - no_space
397
+
398
+ TrailingComma:
399
+ EnforcedStyleForMultiline: no_comma
400
+ SupportedStyles:
401
+ - comma
402
+ - no_comma
403
+
404
+ # TrivialAccessors doesn't require exact name matches and doesn't allow
405
+ # predicated methods by default.
406
+ TrivialAccessors:
407
+ ExactNameMatch: false
408
+ AllowPredicates: false
409
+ Whitelist:
410
+ - to_ary
411
+ - to_a
412
+ - to_c
413
+ - to_enum
414
+ - to_h
415
+ - to_hash
416
+ - to_i
417
+ - to_int
418
+ - to_io
419
+ - to_open
420
+ - to_path
421
+ - to_proc
422
+ - to_r
423
+ - to_regexp
424
+ - to_str
425
+ - to_s
426
+ - to_sym
427
+
428
+ VariableName:
429
+ EnforcedStyle: snake_case
430
+ SupportedStyles:
431
+ - snake_case
432
+ - camelCase
433
+
434
+ WhileUntilModifier:
435
+ MaxLineLength: 79
436
+
437
+ WordArray:
438
+ MinSize: 0
439
+
440
+ Documentation:
441
+ Enabled: false
442
+
443
+ # Compact name spaces
444
+ ClassAndModuleChildren:
445
+ Enabled: false
446
+
447
+ AlignParameters:
448
+ Enabled: false
449
+
450
+ # Unrecognize fail/raise args with custom erors
451
+ RaiseArgs:
452
+ EnforcedStyle: compact
453
+
454
+ LiteralInInterpolation:
455
+ Enabled: false
456
+
457
+ MethodLength:
458
+ Max: 40
459
+
460
+ ##################### Rails ##################################
461
+
462
+ ActionFilter:
463
+ EnforcedStyle: action
464
+ SupportedStyles:
465
+ - action
466
+ - filter
467
+ Include:
468
+ - app/controllers/*.rb
469
+
470
+ DefaultScope:
471
+ Include:
472
+ - app/models/*.rb
473
+
474
+ HasAndBelongsToMany:
475
+ Include:
476
+ - app/models/*.rb
477
+
478
+ ReadWriteAttribute:
479
+ Include:
480
+ - app/models/*.rb
481
+
482
+ ScopeArgs:
483
+ Include:
484
+ - app/models/*.rb
485
+
486
+ Validation:
487
+ Include:
488
+ - app/models/*.rb
489
+
490
+ Encoding:
491
+ Enabled: false
@@ -0,0 +1,5 @@
1
+ nguage: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.3
5
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gemsupport.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'jazz_hands', github: 'nixme/jazz_hands',
8
+ branch: 'bring-your-own-debugger'
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 mdouchement
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ # Gemsupport
2
+ [![Build Status](https://travis-ci.org/mdouchement/gemsupport.svg?branch=master)](https://travis-ci.org/mdouchement/gemsupport)
3
+
4
+ TODO: Write a gem description
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'gemsupport'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install gemsupport
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it ( https://github.com/[my-github-username]/gemsupport/fork )
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:rspec)
6
+ Rubocop::RakeTask.new(:rubocop)
7
+
8
+ task default: :rspec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gemsupport/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'gemsupport'
8
+ spec.version = Gemsupport::VERSION
9
+ spec.authors = ['mdouchement']
10
+ spec.email = ['marc.douchement@predicsis.com']
11
+ spec.summary = %(q{Add support for gem like activesupport, but without Rails})
12
+ spec.description = %(q{Add support for gem like activesupport, but without Rails})
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%(r{^bin/})) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%(r^(test|spec|features)/}))
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
24
+ spec.add_development_dependency 'rubocop', '0.20.0'
25
+ spec.add_development_dependency 'simplecov'
26
+ spec.add_development_dependency 'codeclimate-test-reporter'
27
+ end
@@ -0,0 +1,5 @@
1
+ require 'gemsupport/version'
2
+ require 'gemsupport/core_ext'
3
+
4
+ module Gemsupport
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'gemsupport/core_ext/blank'
2
+ require 'gemsupport/core_ext/string'
3
+ require 'gemsupport/core_ext/hash_keys'
4
+ require 'gemsupport/core_ext/hash'
@@ -0,0 +1,130 @@
1
+ # https://raw.githubusercontent.com/rails/rails/4-1-stable/activesupport/lib/active_support/core_ext/object/blank.rb
2
+ class Object
3
+ # An object is blank if it's false, empty, or a whitespace string.
4
+ # For example, '', ' ', +nil+, [], and {} are all blank.
5
+ #
6
+ # This simplifies
7
+ #
8
+ # address.nil? || address.empty?
9
+ #
10
+ # to
11
+ #
12
+ # address.blank?
13
+ #
14
+ # @return [true, false]
15
+ def blank?
16
+ respond_to?(:empty?) ? !!empty? : !self
17
+ end
18
+
19
+ # An object is present if it's not blank.
20
+ #
21
+ # @return [true, false]
22
+ def present?
23
+ !blank?
24
+ end
25
+
26
+ # Returns the receiver if it's present otherwise returns +nil+.
27
+ # <tt>object.presence</tt> is equivalent to
28
+ #
29
+ # object.present? ? object : nil
30
+ #
31
+ # For example, something like
32
+ #
33
+ # state = params[:state] if params[:state].present?
34
+ # country = params[:country] if params[:country].present?
35
+ # region = state || country || 'US'
36
+ #
37
+ # becomes
38
+ #
39
+ # region = params[:state].presence || params[:country].presence || 'US'
40
+ #
41
+ # @return [Object]
42
+ def presence
43
+ self if present?
44
+ end
45
+ end
46
+
47
+ class NilClass
48
+ # +nil+ is blank:
49
+ #
50
+ # nil.blank? # => true
51
+ #
52
+ # @return [true]
53
+ def blank?
54
+ true
55
+ end
56
+ end
57
+
58
+ class FalseClass
59
+ # +false+ is blank:
60
+ #
61
+ # false.blank? # => true
62
+ #
63
+ # @return [true]
64
+ def blank?
65
+ true
66
+ end
67
+ end
68
+
69
+ class TrueClass
70
+ # +true+ is not blank:
71
+ #
72
+ # true.blank? # => false
73
+ #
74
+ # @return [false]
75
+ def blank?
76
+ false
77
+ end
78
+ end
79
+
80
+ class Array
81
+ # An array is blank if it's empty:
82
+ #
83
+ # [].blank? # => true
84
+ # [1,2,3].blank? # => false
85
+ #
86
+ # @return [true, false]
87
+ alias_method :blank?, :empty?
88
+ end
89
+
90
+ class Hash
91
+ # A hash is blank if it's empty:
92
+ #
93
+ # {}.blank? # => true
94
+ # { key: 'value' }.blank? # => false
95
+ #
96
+ # @return [true, false]
97
+ alias_method :blank?, :empty?
98
+ end
99
+
100
+ class String
101
+ BLANK_RE = /\A[[:space:]]*\z/
102
+
103
+ # A string is blank if it's empty or contains whitespaces only:
104
+ #
105
+ # ''.blank? # => true
106
+ # ' '.blank? # => true
107
+ # "\t\n\r".blank? # => true
108
+ # ' blah '.blank? # => false
109
+ #
110
+ # Unicode whitespace is supported:
111
+ #
112
+ # "\u00a0".blank? # => true
113
+ #
114
+ # @return [true, false]
115
+ def blank?
116
+ BLANK_RE === self
117
+ end
118
+ end
119
+
120
+ class Numeric #:nodoc:
121
+ # No number is blank:
122
+ #
123
+ # 1.blank? # => false
124
+ # 0.blank? # => false
125
+ #
126
+ # @return [false]
127
+ def blank?
128
+ false
129
+ end
130
+ end
@@ -0,0 +1,15 @@
1
+ Hash.class_eval do
2
+ def deep_merge(hsh)
3
+ merger = proc do |key, v1, v2|
4
+ v1.kind_of?(Hash) && v2.kind_of?(Hash) ? v1.merge(v2, &merger) : v2
5
+ end
6
+ self.merge(hsh, &merger)
7
+ end
8
+
9
+ def deep_merge!(hsh)
10
+ merger = proc do |key, v1, v2|
11
+ v1.kind_of?(Hash) && v2.kind_of?(Hash) ? v1.merge(v2, &merger) : v2
12
+ end
13
+ self.merge!(hsh, &merger)
14
+ end
15
+ end
@@ -0,0 +1,163 @@
1
+ # Extract from https://github.com/rails/rails/blob/4-1-stable/activesupport/lib/active_support/core_ext/hash/keys.rb
2
+ class Hash
3
+ # Returns a new hash with all keys converted using the block operation.
4
+ #
5
+ # hash = { name: 'Rob', age: '28' }
6
+ #
7
+ # hash.transform_keys{ |key| key.to_s.upcase }
8
+ # # => {"NAME"=>"Rob", "AGE"=>"28"}
9
+ def transform_keys
10
+ result = {}
11
+ each_key do |key|
12
+ result[yield(key)] = self[key]
13
+ end
14
+ result
15
+ end
16
+
17
+ # Destructively convert all keys using the block operations.
18
+ # Same as transform_keys but modifies +self+.
19
+ def transform_keys!
20
+ keys.each do |key|
21
+ self[yield(key)] = delete(key)
22
+ end
23
+ self
24
+ end
25
+
26
+ # Returns a new hash with all keys converted to strings.
27
+ #
28
+ # hash = { name: 'Rob', age: '28' }
29
+ #
30
+ # hash.stringify_keys
31
+ # # => { "name" => "Rob", "age" => "28" }
32
+ def stringify_keys
33
+ transform_keys{ |key| key.to_s }
34
+ end
35
+
36
+ # Destructively convert all keys to strings. Same as
37
+ # +stringify_keys+, but modifies +self+.
38
+ def stringify_keys!
39
+ transform_keys!{ |key| key.to_s }
40
+ end
41
+
42
+ # Returns a new hash with all keys converted to symbols, as long as
43
+ # they respond to +to_sym+.
44
+ #
45
+ # hash = { 'name' => 'Rob', 'age' => '28' }
46
+ #
47
+ # hash.symbolize_keys
48
+ # # => { name: "Rob", age: "28" }
49
+ def symbolize_keys
50
+ transform_keys{ |key| key.to_sym rescue key }
51
+ end
52
+ alias_method :to_options, :symbolize_keys
53
+
54
+ # Destructively convert all keys to symbols, as long as they respond
55
+ # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
56
+ def symbolize_keys!
57
+ transform_keys!{ |key| key.to_sym rescue key }
58
+ end
59
+ alias_method :to_options!, :symbolize_keys!
60
+
61
+ # Validate all keys in a hash match <tt>*valid_keys</tt>, raising ArgumentError
62
+ # on a mismatch. Note that keys are NOT treated indifferently, meaning if you
63
+ # use strings for keys but assert symbols as keys, this will fail.
64
+ #
65
+ # { name: 'Rob', years: '28' }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age"
66
+ # { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age') # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'"
67
+ # { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
68
+ def assert_valid_keys(*valid_keys)
69
+ valid_keys.flatten!
70
+ each_key do |k|
71
+ unless valid_keys.include?(k)
72
+ raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}")
73
+ end
74
+ end
75
+ end
76
+
77
+ # Returns a new hash with all keys converted by the block operation.
78
+ # This includes the keys from the root hash and from all
79
+ # nested hashes and arrays.
80
+ #
81
+ # hash = { person: { name: 'Rob', age: '28' } }
82
+ #
83
+ # hash.deep_transform_keys{ |key| key.to_s.upcase }
84
+ # # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
85
+ def deep_transform_keys(&block)
86
+ _deep_transform_keys_in_object(self, &block)
87
+ end
88
+
89
+ # Destructively convert all keys by using the block operation.
90
+ # This includes the keys from the root hash and from all
91
+ # nested hashes and arrays.
92
+ def deep_transform_keys!(&block)
93
+ _deep_transform_keys_in_object!(self, &block)
94
+ end
95
+
96
+ # Returns a new hash with all keys converted to strings.
97
+ # This includes the keys from the root hash and from all
98
+ # nested hashes and arrays.
99
+ #
100
+ # hash = { person: { name: 'Rob', age: '28' } }
101
+ #
102
+ # hash.deep_stringify_keys
103
+ # # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
104
+ def deep_stringify_keys
105
+ deep_transform_keys{ |key| key.to_s }
106
+ end
107
+
108
+ # Destructively convert all keys to strings.
109
+ # This includes the keys from the root hash and from all
110
+ # nested hashes and arrays.
111
+ def deep_stringify_keys!
112
+ deep_transform_keys!{ |key| key.to_s }
113
+ end
114
+
115
+ # Returns a new hash with all keys converted to symbols, as long as
116
+ # they respond to +to_sym+. This includes the keys from the root hash
117
+ # and from all nested hashes and arrays.
118
+ #
119
+ # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
120
+ #
121
+ # hash.deep_symbolize_keys
122
+ # # => {:person=>{:name=>"Rob", :age=>"28"}}
123
+ def deep_symbolize_keys
124
+ deep_transform_keys{ |key| key.to_sym rescue key }
125
+ end
126
+
127
+ # Destructively convert all keys to symbols, as long as they respond
128
+ # to +to_sym+. This includes the keys from the root hash and from all
129
+ # nested hashes and arrays.
130
+ def deep_symbolize_keys!
131
+ deep_transform_keys!{ |key| key.to_sym rescue key }
132
+ end
133
+
134
+ private
135
+ # support methods for deep transforming nested hashes and arrays
136
+ def _deep_transform_keys_in_object(object, &block)
137
+ case object
138
+ when Hash
139
+ object.each_with_object({}) do |(key, value), result|
140
+ result[yield(key)] = _deep_transform_keys_in_object(value, &block)
141
+ end
142
+ when Array
143
+ object.map {|e| _deep_transform_keys_in_object(e, &block) }
144
+ else
145
+ object
146
+ end
147
+ end
148
+
149
+ def _deep_transform_keys_in_object!(object, &block)
150
+ case object
151
+ when Hash
152
+ object.keys.each do |key|
153
+ value = object.delete(key)
154
+ object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
155
+ end
156
+ object
157
+ when Array
158
+ object.map! {|e| _deep_transform_keys_in_object!(e, &block)}
159
+ else
160
+ object
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,16 @@
1
+ String.class_eval do
2
+ def underscore
3
+ gsub(/::/, '/')
4
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
5
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
6
+ .tr('-', '_')
7
+ .downcase
8
+ end
9
+
10
+ def camelize
11
+ return self if self !~ /_/ && self =~ /[A-Z]+.*/
12
+ split('/').map do |e|
13
+ e.split('_').map { |w| w.capitalize }.join
14
+ end.join('::')
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Gemsupport
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ class EmptyTrue
4
+ def empty?
5
+ 0
6
+ end
7
+ end
8
+
9
+ class EmptyFalse
10
+ def empty?
11
+ nil
12
+ end
13
+ end
14
+
15
+ describe 'blank' do
16
+ context 'when it is a blank object' do
17
+ [EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", ' ', "\u00a0", [], {}].each do |blank_value|
18
+ describe "#{blank_value.class}#blank?" do
19
+ it 'returns true' do
20
+ expect(blank_value.blank?).to be(true)
21
+ end
22
+ end
23
+
24
+ describe "#{blank_value.class}#present?" do
25
+ it 'returns false' do
26
+ expect(blank_value.present?).to be(false)
27
+ end
28
+ end
29
+
30
+ describe "#{blank_value.class}#presence" do
31
+ it 'returns nil' do
32
+ expect(blank_value.presence).to be(nil)
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ context 'when it is not a blank object' do
39
+ [EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 }].each do |not_blank_value|
40
+ describe "#{not_blank_value.class}#blank?" do
41
+ it 'returns false' do
42
+ expect(not_blank_value.blank?).to be(false)
43
+ end
44
+ end
45
+
46
+ describe "#{not_blank_value.class}#present?" do
47
+ it 'returns true' do
48
+ expect(not_blank_value.present?).to be(true)
49
+ end
50
+ end
51
+
52
+ describe "#{not_blank_value.class}#presence" do
53
+ it 'returns the value' do
54
+ expect(not_blank_value.presence).to be(not_blank_value)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+ let(:simple) do
5
+ {
6
+ strings: { 'a' => 1, 'b' => 2 },
7
+ upcase_strings: { 'A' => 1, 'B' => 2 },
8
+ symbols: { a: 1, b: 2 },
9
+ mixed: { 'a' => 1, b: 2 },
10
+ fixnums: { 0 => 1, 1 => 2 }
11
+ }
12
+ end
13
+
14
+ let(:nested) do
15
+ {
16
+ strings: { 'a' => { 'b' => { 'c' => 3 } } },
17
+ upcase_strings: { 'A' => { 'B' => { 'C' => 3 } } },
18
+ symbols: { a: { b: { c: 3 } } },
19
+ mixed: { 'a' => { b: { 'c' => 3 } } },
20
+ fixnums: { 0 => { 1 => { 'c' => 3 } } }
21
+ }
22
+ end
23
+
24
+ describe '#transform_keys' do
25
+ # to long to write and already tested from activesupport
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+ let(:input_a) do
5
+ { a: { b: { c: 3 } } }
6
+ end
7
+
8
+ let(:input_b) do
9
+ { a: { b: { d: 4 } } }
10
+ end
11
+
12
+ let(:result_ab) do
13
+ { a: { b: { c: 3, d: 4 } } }
14
+ end
15
+
16
+ describe '#deep_merge' do
17
+ it 'merges all the values and returns new_hsh' do
18
+ expect(input_a.deep_merge(input_b)).to eq(result_ab)
19
+ end
20
+ end
21
+
22
+ describe '#deep_merge!' do
23
+ it 'merges all the values and returns hsh' do
24
+ input_a_cp = input_a.clone
25
+ input_a_cp.deep_merge!(input_b)
26
+ expect(input_a_cp).to eq(result_ab)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'String' do
4
+ describe '#underscore' do
5
+ context 'when snake_case word' do
6
+ it 'does nothing' do
7
+ expect('product'.underscore).to eq('product')
8
+ end
9
+ end
10
+
11
+ context 'when Capitalized word' do
12
+ it 'succeeds' do
13
+ expect('Product'.underscore).to eq('product')
14
+ end
15
+ end
16
+
17
+ context 'when CamelCase word that contains digits' do
18
+ it 'succeeds' do
19
+ expect('Product22Owner56'.underscore).to eq('product22_owner56')
20
+ end
21
+ end
22
+
23
+ context 'when CamelCase word' do
24
+ it 'succeeds' do
25
+ expect('ProductOwner'.underscore).to eq('product_owner')
26
+ end
27
+ end
28
+
29
+ context 'when namespaced CamelCase word' do
30
+ it 'succeeds' do
31
+ expect('Rails::ProductOwner'.underscore).to eq('rails/product_owner')
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#camelize' do
37
+ context 'when CamelCase word' do
38
+ it 'does nothing' do
39
+ expect('ProductOwner'.camelize).to eq('ProductOwner')
40
+ end
41
+ end
42
+
43
+ context 'when snake_case' do
44
+ it 'succeeds' do
45
+ expect('product_owner'.camelize).to eq('ProductOwner')
46
+ end
47
+ end
48
+
49
+ context 'when snake_case word that contains digits' do
50
+ it 'succeeds' do
51
+ expect('product22_owner56'.camelize).to eq('Product22Owner56')
52
+ end
53
+ end
54
+
55
+ context 'when namespaced snake_case word' do
56
+ it 'succeeds' do
57
+ expect('rails/kmlio/product_owner'.camelize).to eq('Rails::Kmlio::ProductOwner')
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,26 @@
1
+ # CodeClimate relative stuff
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+
5
+ require 'simplecov'
6
+ SimpleCov.start
7
+
8
+ require 'gemsupport'
9
+
10
+ # This file was generated by the `rspec --init` command. Conventionally, all
11
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
12
+ # Require this file using `require "spec_helper"` to ensure that it is only
13
+ # loaded once.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+
21
+ # Run specs in random order to surface order dependencies. If you find an
22
+ # order dependency and want to debug it, you can fix the order by providing
23
+ # the seed, which is printed after each run.
24
+ # --seed 1234
25
+ config.order = 'random'
26
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemsupport
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - mdouchement
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.1.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.20.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.20.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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: q{Add support for gem like activesupport, but without Rails}
98
+ email:
99
+ - marc.douchement@predicsis.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - gemsupport.gemspec
112
+ - lib/gemsupport.rb
113
+ - lib/gemsupport/core_ext.rb
114
+ - lib/gemsupport/core_ext/blank.rb
115
+ - lib/gemsupport/core_ext/hash.rb
116
+ - lib/gemsupport/core_ext/hash_keys.rb
117
+ - lib/gemsupport/core_ext/string.rb
118
+ - lib/gemsupport/version.rb
119
+ - spec/gemsupport/core_ext/blank_spec.rb
120
+ - spec/gemsupport/core_ext/hash_keys_spec.rb
121
+ - spec/gemsupport/core_ext/hash_spec.rb
122
+ - spec/gemsupport/core_ext/string_spec.rb
123
+ - spec/spec_helper.rb
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: q{Add support for gem like activesupport, but without Rails}
148
+ test_files: []
149
+ has_rdoc: