cardamom 0.1.1 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4564f64ee543d1f15c131212984a69bb1517c618
4
- data.tar.gz: 3e2d98b3c72d77dbb0dc269cfe1a948a88021eb5
3
+ metadata.gz: a4d944e96c6f06754f9be9a7d390c393cfa4c9fa
4
+ data.tar.gz: d1804add323958228150ce9e6ca5463104e3e519
5
5
  SHA512:
6
- metadata.gz: 973fa955b05ed8c8621d0860e4452edb5f7af1f9a0ff76eb7b383e0f7d3ed42a35dc60b9dd63633908675b3c59a2cbb5258e5873449958b791cfe94aeba4d0f3
7
- data.tar.gz: 7897030f0574ff174061880af8c8d9d0628f53cb188e386da291f65fe7a8d187ab20aef96a95a83104da88efe5e0ea70f6a33691b819b75976663d7e4b6c53f9
6
+ metadata.gz: cb6433ec91a48bee667b843c513f8ecd1a0f35399ffed0571da782e758a196bfbc4c645fc3b68a65bab57204aa13e3cb5dd981e1a6fafd6347106a432e417f87
7
+ data.tar.gz: 2753ab51fc3c780e4abb707ba7b8d65763e2b12b654e0212e438175fb3828b29fe2aee85244859a7e1831dd1f0f1eb204c3c18c5da8a576a5cd46a84958fd784
data/.travis.yml CHANGED
@@ -5,7 +5,9 @@ rvm:
5
5
  - jruby-19mode
6
6
  - rbx-2
7
7
  install:
8
+ - gem install cuba
8
9
  - gem install multi_json
10
+ - gem install unicode_utils
9
11
  - gem install cutest -v 1.1.3
10
12
  - gem install codeclimate-test-reporter
11
13
  script:
data/README.md CHANGED
@@ -28,7 +28,7 @@ Only use what you need. For instance, if you just want to use ```string_helpers`
28
28
  ```ruby
29
29
  require 'cardamom/string_helpers'
30
30
 
31
- Cuba.plugin StringHelpers
31
+ Cuba.plugin Cardamom::StringHelpers
32
32
  ```
33
33
 
34
34
  To use ALL helpers available:
@@ -46,3 +46,7 @@ As of today, available helpers are:
46
46
  - HashHelpers
47
47
  - JsonHelpers
48
48
  - ResponseHelpers
49
+
50
+ ## License
51
+
52
+ Cardamom is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/cardamom.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cardamom"
3
- s.version = "0.1.1"
3
+ s.version = "0.2.0"
4
4
  s.summary = "Cardamom: Spice up your Cuba app!"
5
5
  s.description = "Helpers for Cuba apps"
6
6
  s.authors = ["matiasow"]
@@ -1,39 +1,41 @@
1
1
  require 'cardamom/string_helpers'
2
2
 
3
- module HashHelpers
4
- def symbolize_keys(hash)
5
- result = {}
6
- hash.each do |k, v|
7
- new_k = ( k.is_a?(String) && k.to_sym ) || k
8
- new_v = ( v.is_a?(Hash) && symbolize_keys(v) ) || v
9
- result[new_k] = new_v
3
+ module Cardamom
4
+ module HashHelpers
5
+ def symbolize_keys(hash)
6
+ result = {}
7
+ hash.each do |k, v|
8
+ new_k = ( k.is_a?(String) && k.to_sym ) || k
9
+ new_v = ( v.is_a?(Hash) && symbolize_keys(v) ) || v
10
+ result[new_k] = new_v
11
+ end
12
+ result
10
13
  end
11
- result
12
- end
13
14
 
14
- def underscore_keys(hash)
15
- transform_keys(hash){ |k| underscore(k.to_s) }
16
- end
15
+ def underscore_keys(hash)
16
+ transform_keys(hash){ |k| underscore(k.to_s) }
17
+ end
17
18
 
18
- def camelize_keys(hash)
19
- transform_keys(hash){ |k| camelize(k.to_s) }
20
- end
19
+ def camelize_keys(hash)
20
+ transform_keys(hash){ |k| camelize(k.to_s) }
21
+ end
21
22
 
22
- def stringify_keys(hash)
23
- transform_keys(hash){ |k| k.to_s }
24
- end
23
+ def stringify_keys(hash)
24
+ transform_keys(hash){ |k| k.to_s }
25
+ end
25
26
 
26
- def select_keys(hash, *args)
27
- hash.select {|k,v| args.include?(k) }
28
- end
27
+ def select_keys(hash, *args)
28
+ hash.select {|k,v| args.include?(k) }
29
+ end
29
30
 
30
- def transform_keys(hash, &block)
31
- result = {}
32
- hash.each do |k, v|
33
- new_k = k.is_a?(String) || k.is_a?(Symbol) ? block.call(k.to_s) : k
34
- new_v = v.is_a?(Hash) ? transform_keys(v, &block) : v
35
- result[new_k] = new_v
31
+ def transform_keys(hash, &block)
32
+ result = {}
33
+ hash.each do |k, v|
34
+ new_k = k.is_a?(String) || k.is_a?(Symbol) ? block.call(k.to_s) : k
35
+ new_v = v.is_a?(Hash) ? transform_keys(v, &block) : v
36
+ result[new_k] = new_v
37
+ end
38
+ result
36
39
  end
37
- result
38
40
  end
39
41
  end
@@ -1,18 +1,20 @@
1
1
  require 'cuba'
2
2
 
3
- module JsonHelpers
4
- def json_payload
5
- body = req.body.read
6
- body && MultiJson.load(body)
7
- end
3
+ module Cardamom
4
+ module JsonHelpers
5
+ def json_payload
6
+ body = req.body.read
7
+ body && MultiJson.load(body)
8
+ end
8
9
 
9
- def parse_json(json)
10
- MultiJson.load(json, symbolize_keys: true)
11
- end
10
+ def parse_json(json)
11
+ MultiJson.load(json, symbolize_keys: true)
12
+ end
12
13
 
13
- def json(status, data)
14
- res.status = status
15
- res.headers["Content-Type"] = "application/json"
16
- res.write MultiJson.dump(data)
14
+ def json(status, data)
15
+ res.status = status
16
+ res.headers["Content-Type"] = "application/json"
17
+ res.write MultiJson.dump(data)
18
+ end
17
19
  end
18
- end
20
+ end
@@ -1,21 +1,23 @@
1
1
  require 'cuba'
2
2
 
3
- module ResponseHelpers
4
- def bad_request(message)
5
- res.status = 400
6
- res.write message
7
- halt res.finish
8
- end
3
+ module Cardamom
4
+ module ResponseHelpers
5
+ def bad_request(message)
6
+ res.status = 400
7
+ res.write message
8
+ halt res.finish
9
+ end
9
10
 
10
- def unauthorized_request(message = nil)
11
- res.status = 401
12
- res.write (message || '401 Unauthorized')
13
- halt res.finish
14
- end
11
+ def unauthorized_request(message = nil)
12
+ res.status = 401
13
+ res.write (message || '401 Unauthorized')
14
+ halt res.finish
15
+ end
15
16
 
16
- def not_found_request(message = nil)
17
- res.status = 404
18
- res.write (message || '404 Not found')
19
- halt res.finish
17
+ def not_found_request(message = nil)
18
+ res.status = 404
19
+ res.write (message || '404 Not found')
20
+ halt res.finish
21
+ end
20
22
  end
21
- end
23
+ end
@@ -1,58 +1,60 @@
1
1
  require 'unicode_utils'
2
2
 
3
- module StringHelpers
4
- # Upcase unicode string
5
- def upcase(str)
6
- UnicodeUtils.upcase(str)
7
- end
3
+ module Cardamom
4
+ module StringHelpers
5
+ # Upcase unicode string
6
+ def upcase(str)
7
+ UnicodeUtils.upcase(str)
8
+ end
8
9
 
9
- # Downcase unicode string
10
- def downcase(str)
11
- UnicodeUtils.downcase(str)
12
- end
10
+ # Downcase unicode string
11
+ def downcase(str)
12
+ UnicodeUtils.downcase(str)
13
+ end
13
14
 
14
- # Camelize string
15
- #
16
- # Example:
17
- # camelize 'camelize_this_string'
18
- # => 'CamelizeThisString'
19
- def camelize(str)
20
- s = str.to_s.dup
21
- s.sub!(/^[a-z\d]*/) { $&.capitalize }
22
- s.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
23
- s.gsub!(/\//, '::')
24
- s
25
- end
15
+ # Camelize string
16
+ #
17
+ # Example:
18
+ # camelize 'camelize_this_string'
19
+ # => 'CamelizeThisString'
20
+ def camelize(str)
21
+ s = str.to_s.dup
22
+ s.sub!(/^[a-z\d]*/) { $&.capitalize }
23
+ s.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
24
+ s.gsub!(/\//, '::')
25
+ s
26
+ end
26
27
 
27
- # Underscore string
28
- #
29
- # Example:
30
- # underscore 'UnderscoreThisString'
31
- # => 'underscore_this_string'
32
- def underscore(str)
33
- s = str.to_s.dup
34
- return s unless s =~ /[A-Z-]|::/
35
- s.gsub!(/::/, '/')
36
- s.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.to_s.downcase}" }
37
- s.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
38
- s.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
39
- s.tr!("-", "_")
40
- s.downcase!
41
- s[0..-2]
42
- end
28
+ # Underscore string
29
+ #
30
+ # Example:
31
+ # underscore 'UnderscoreThisString'
32
+ # => 'underscore_this_string'
33
+ def underscore(str)
34
+ s = str.to_s.dup
35
+ return s unless s =~ /[A-Z-]|::/
36
+ s.gsub!(/::/, '/')
37
+ s.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.to_s.downcase}" }
38
+ s.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
39
+ s.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
40
+ s.tr!("-", "_")
41
+ s.downcase!
42
+ s[0..-2]
43
+ end
43
44
 
44
- # Sanitize a "dirty" string by removing dots, dashes, slashes, apostrophes, multiple spaces, etc.
45
- # Specially useful for data cleansing routines
46
- #
47
- # Example:
48
- # sanitize_dirty_string "Ge-o/rg.e O'Hara"
49
- # => "George O Hara"
50
- def sanitize_dirty_string(str)
51
- str.to_s.strip.gsub(".", "")
52
- .gsub("-", "")
53
- .gsub("_", "")
54
- .gsub("/", "")
55
- .gsub("'", " ")
56
- .gsub(/\s+/, ' ')
45
+ # Sanitize a "dirty" string by removing dots, dashes, slashes, apostrophes, multiple spaces, etc.
46
+ # Specially useful for data cleansing routines
47
+ #
48
+ # Example:
49
+ # sanitize_dirty_string "Ge-o/rg.e O'Hara"
50
+ # => "George O Hara"
51
+ def sanitize_dirty_string(str)
52
+ str.to_s.strip.gsub(".", "")
53
+ .gsub("-", "")
54
+ .gsub("_", "")
55
+ .gsub("/", "")
56
+ .gsub("'", " ")
57
+ .gsub(/\s+/, ' ')
58
+ end
57
59
  end
58
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cardamom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - matiasow
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-24 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cuba