radriar 0.1.0.alpha.1 → 0.1.0.alpha.2
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/TODO.md +1 -0
- data/lib/radriar/api/context.rb +1 -0
- data/lib/radriar/grape.rb +3 -3
- data/lib/radriar/representable.rb +6 -3
- data/lib/radriar/roar/key_translation.rb +42 -17
- data/lib/radriar/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57ea1f5b5028c2d60f066bccee36a662244afee1
|
4
|
+
data.tar.gz: bdaacb50e3f2dff27b6dee7fc8193cc1286ea984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81064a99af29b82f73cdba951a496ff56457bd1e21066c8dd56bffaffc323b06d4f57ffb65def6242c1077d11b837831d4be438b11edc2c3eae2fa5c9ef1e0ec
|
7
|
+
data.tar.gz: 14c0d00e8d89a439a00f8bce1e78bdf3301d39e932c1120086a9cbd2aa52462cd0330101b6245c3d6b4a84f8e889484e79101842304ccef4d690dd37216eeab5
|
data/TODO.md
CHANGED
data/lib/radriar/api/context.rb
CHANGED
data/lib/radriar/grape.rb
CHANGED
@@ -20,12 +20,12 @@ class ::Grape::API
|
|
20
20
|
helpers Radriar::API::Context
|
21
21
|
helpers Radriar::API::StrongParametersSupport
|
22
22
|
helpers Radriar::Roar::Representers
|
23
|
+
include Radriar::Roar::KeyTranslation
|
24
|
+
include Radriar::Roar::HAL
|
23
25
|
|
24
26
|
Radriar::Representable.representer_namespace = representer_namespace
|
25
27
|
Radriar::Representable.hypermedia = hypermedia
|
26
|
-
|
27
|
-
include Radriar::Roar::KeyTranslation if translate_keys
|
28
|
-
include Radriar::Roar::HAL
|
28
|
+
Radriar::Representable.translate_keys = translate_keys
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
module Radriar
|
2
2
|
module Representable
|
3
3
|
mattr_accessor :representer_namespace
|
4
|
-
mattr_accessor :hypermedia
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
[:hypermedia, :translate_keys].each do |option|
|
6
|
+
mattr_accessor option.to_sym
|
7
|
+
|
8
|
+
self.define_singleton_method "#{option}?".to_sym do
|
9
|
+
!!send(option.to_sym)
|
10
|
+
end
|
8
11
|
end
|
9
12
|
end
|
10
13
|
end
|
@@ -4,6 +4,47 @@ module Radriar
|
|
4
4
|
module KeyTranslation
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
|
+
included do
|
8
|
+
unless ::Representable::Hash.instance_methods.include?(:__radriar_old_to_hash)
|
9
|
+
::Representable::Hash.module_eval do
|
10
|
+
# TODO: Module#prepend giving too much headache
|
11
|
+
alias_method :__radriar_old_to_hash, :to_hash
|
12
|
+
alias_method :__radriar_old_from_hash, :from_hash
|
13
|
+
|
14
|
+
define_method(:from_hash) do |data, options={}, binding_builder=::Representable::Hash::PropertyBinding|
|
15
|
+
if Radriar::Representable.translate_keys?
|
16
|
+
data = filter_wrap(UnderscoreKeys.new(data), options)
|
17
|
+
update_properties_from(data, options, binding_builder)
|
18
|
+
else
|
19
|
+
__radriar_old_from_hash(data, options, binding_builder)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
define_method(:to_hash) do |options={}, binding_builder=::Representable::Hash::PropertyBinding|
|
24
|
+
if Radriar::Representable.translate_keys?
|
25
|
+
CamelizeKeys.new(__radriar_old_to_hash(options, binding_builder))
|
26
|
+
else
|
27
|
+
__radriar_old_to_hash(options, binding_builder)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
unless ::Grape::Endpoint.instance_methods.include?(:__radriar_old_params)
|
34
|
+
::Grape::Endpoint.class_eval do
|
35
|
+
alias_method :__radriar_old_params, :params
|
36
|
+
|
37
|
+
define_method(:params) do
|
38
|
+
if Radriar::Representable.translate_keys?
|
39
|
+
@params ||= UnderscoreKeys.new(@request.params)
|
40
|
+
else
|
41
|
+
__radriar_old_params
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
7
48
|
class KeyTranslatorHash < Hashie::Mash
|
8
49
|
protected
|
9
50
|
def convert_key(key)
|
@@ -33,25 +74,9 @@ module Radriar
|
|
33
74
|
class CamelizeKeys < KeyTranslatorHash
|
34
75
|
protected
|
35
76
|
def convert_key(key)
|
36
|
-
key.to_s.camelize(:lower)
|
77
|
+
key.to_s.start_with?("_") ? key.to_s : key.to_s.camelize(:lower)
|
37
78
|
end
|
38
79
|
end
|
39
|
-
|
40
|
-
|
41
|
-
module Representer
|
42
|
-
def from_hash(data, options={}, binding_builder=::Representable::Hash::PropertyBinding)
|
43
|
-
data = filter_wrap(UnderscoreKeys.new(data), options)
|
44
|
-
update_properties_from(data, options, binding_builder)
|
45
|
-
end
|
46
|
-
|
47
|
-
def to_hash(options={}, binding_builder=::Representable::Hash::PropertyBinding)
|
48
|
-
CamelizeKeys.new(super)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
included do
|
53
|
-
::Representable::Hash.prepend(Representer)
|
54
|
-
end
|
55
80
|
end
|
56
81
|
end
|
57
82
|
end
|
data/lib/radriar/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radriar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.alpha.
|
4
|
+
version: 0.1.0.alpha.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Perez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|