inflect 0.3.3 → 0.4.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 +4 -4
- data/lib/inflect/director.rb +8 -2
- data/lib/inflect/response.rb +20 -0
- data/lib/inflect/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8951661906e8fea2c53b241c2ed44d49d7f4155f
|
4
|
+
data.tar.gz: e685535c15abc2f5f753f9c1ea42ed8d372edf89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25ef3d073b0ab588ac592a502767345cc8dfb4a8454f777d98aa210bd78d59d2cbcd8004f9ff06cc814f513122f76b2372d2d054c1229231ac6b0fc99ea7e4dd
|
7
|
+
data.tar.gz: 8f181a6082230a3bf07145320597429314e6387dde91254603f7f9d441e0f547b6871155ddc01027ae7b1c4187d42e83d53a9adb75d5770bd0fad369f72349a6
|
data/lib/inflect/director.rb
CHANGED
@@ -21,13 +21,19 @@ module Inflect
|
|
21
21
|
# @param words [Array<String, Symbol>]
|
22
22
|
def handle(words)
|
23
23
|
selected_service = select_service(words)
|
24
|
-
|
24
|
+
if selected_service.nil?
|
25
|
+
raise "No service can respond to #{words.first}"
|
26
|
+
else
|
27
|
+
selected_service.serve(words)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
private
|
28
32
|
|
29
33
|
def select_service(words)
|
30
|
-
services.find
|
34
|
+
services.find do |service|
|
35
|
+
service.valid?(words)
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
33
39
|
end
|
data/lib/inflect/response.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'inflect/loader'
|
2
2
|
require 'inflect/i18n'
|
3
|
+
require 'json'
|
3
4
|
|
4
5
|
module Inflect
|
5
6
|
#Responsible of encapsulate all the content of the service response.
|
@@ -50,6 +51,21 @@ module Inflect
|
|
50
51
|
end.all?
|
51
52
|
end
|
52
53
|
|
54
|
+
# Returns the Object as Hash
|
55
|
+
# @return Hash
|
56
|
+
def to_hash
|
57
|
+
attrs = {}
|
58
|
+
vars = splitted_instance_variables
|
59
|
+
vars.each { |var| attrs[var.to_s] = send(var) }
|
60
|
+
attrs
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns the response in json format
|
64
|
+
# @return String
|
65
|
+
def to_json
|
66
|
+
to_hash.to_json
|
67
|
+
end
|
68
|
+
|
53
69
|
private
|
54
70
|
|
55
71
|
def valid_attribute_content
|
@@ -59,5 +75,9 @@ module Inflect
|
|
59
75
|
end
|
60
76
|
true
|
61
77
|
end
|
78
|
+
|
79
|
+
def splitted_instance_variables
|
80
|
+
instance_variables.map { |var| var.to_s.split('@')[1] }
|
81
|
+
end
|
62
82
|
end
|
63
83
|
end
|
data/lib/inflect/version.rb
CHANGED