mini-apivore 0.1.3 → 0.1.4

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: 1a2ff16bbe47627dd76eafc59d94cae91b501034
4
- data.tar.gz: 3a8ec7035ef427ca51957a5d9510c19c0a234403
3
+ metadata.gz: b3ec77a52357819182bf812f94a54a82c1972c36
4
+ data.tar.gz: 88670eeab470922d7c5e4b46acab2822ca493b3e
5
5
  SHA512:
6
- metadata.gz: 4e50be1f1d5348fe087074e7a6ce0ade7a2b01edb2d7b56460fe22a52ce8b5b0158eef60ce2d2b8c28c59d7d00acf5fa67c97580c6322f14c4466bd5c560b113
7
- data.tar.gz: c96d11b96a7a392cfa2e6fe2e2bf530a071acdc047af2f7b832671a760ee4eea51d35c9d085f91efb2da0a500bc86392ab87434fba3e7039674812d0d053ee80
6
+ metadata.gz: 8eda4b6a71a1269c2e2cf94681de397a4159a77771f1682684250bb3762734aa66fed729daa12980c7492ffcfeaad4ceea9b9875ccf85d0643fed1134554162b
7
+ data.tar.gz: a8bc5d6ea1d31c75ad90c44f4900c77445856d9caba143196f23d3fae3b191692ad029565f733f8d81b2d62a6ed28180c237af3eeb32c59c61480927c87ed674
data/lib/mini_apivore.rb CHANGED
@@ -5,6 +5,7 @@ require 'mini_apivore/swagger'
5
5
  require 'mini_apivore/swagger_checker'
6
6
  require 'mini_apivore/validation'
7
7
  require 'mini_apivore/http_codes'
8
+ require 'mini_apivore/to_param'
8
9
 
9
10
  module MiniApivore
10
11
  SWAGGER_CHECKERS = {}
@@ -0,0 +1,84 @@
1
+ require "cgi"
2
+
3
+ class Object
4
+ # Alias of <tt>to_s</tt>.
5
+ def to_param
6
+ to_s
7
+ end
8
+
9
+ # Converts an object into a string suitable for use as a URL query string,
10
+ # using the given <tt>key</tt> as the param name.
11
+ def to_query(key)
12
+ "#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
13
+ end
14
+ end unless Object.method_defined?( :to_param )
15
+
16
+ class NilClass
17
+ # Returns +self+.
18
+ def to_param
19
+ self
20
+ end
21
+ end unless NilClass.method_defined?( :to_param )
22
+
23
+ class TrueClass
24
+ # Returns +self+.
25
+ def to_param
26
+ self
27
+ end
28
+ end unless TrueClass.method_defined?( :to_param )
29
+
30
+ class FalseClass
31
+ # Returns +self+.
32
+ def to_param
33
+ self
34
+ end
35
+ end unless FalseClass.method_defined?( :to_param )
36
+
37
+ class Array
38
+ # Calls <tt>to_param</tt> on all its elements and joins the result with
39
+ # slashes. This is used by <tt>url_for</tt> in Action Pack.
40
+ def to_param
41
+ collect(&:to_param).join "/"
42
+ end
43
+
44
+ # Converts an array into a string suitable for use as a URL query string,
45
+ # using the given +key+ as the param name.
46
+ #
47
+ # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
48
+ def to_query(key)
49
+ prefix = "#{key}[]"
50
+
51
+ if empty?
52
+ nil.to_query(prefix)
53
+ else
54
+ collect { |value| value.to_query(prefix) }.join "&"
55
+ end
56
+ end
57
+ end unless Array.method_defined?( :to_param )
58
+
59
+ class Hash
60
+ # Returns a string representation of the receiver suitable for use as a URL
61
+ # query string:
62
+ #
63
+ # {name: 'David', nationality: 'Danish'}.to_query
64
+ # # => "name=David&nationality=Danish"
65
+ #
66
+ # An optional namespace can be passed to enclose key names:
67
+ #
68
+ # {name: 'David', nationality: 'Danish'}.to_query('user')
69
+ # # => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
70
+ #
71
+ # The string pairs "key=value" that conform the query string
72
+ # are sorted lexicographically in ascending order.
73
+ #
74
+ # This method is also aliased as +to_param+.
75
+ def to_query(namespace = nil)
76
+ collect do |key, value|
77
+ unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
78
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
79
+ end
80
+ end.compact.sort! * "&"
81
+ end
82
+
83
+ alias_method :to_param, :to_query
84
+ end unless Hash.method_defined?( :to_param )
@@ -1,5 +1,5 @@
1
1
  module Mini
2
2
  module Apivore
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini-apivore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-09 00:00:00.000000000 Z
11
+ date: 2018-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -96,6 +96,7 @@ files:
96
96
  - lib/mini_apivore/http_codes.rb
97
97
  - lib/mini_apivore/swagger.rb
98
98
  - lib/mini_apivore/swagger_checker.rb
99
+ - lib/mini_apivore/to_param.rb
99
100
  - lib/mini_apivore/validation.rb
100
101
  - lib/mini_apivore/version.rb
101
102
  homepage: https://github.com/alekseyl/mini-apivore