cyrax 0.3.2 → 0.3.3
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 +14 -6
- data/lib/cyrax.rb +1 -0
- data/lib/cyrax/decorator.rb +1 -7
- data/lib/cyrax/extensions/has_response.rb +1 -0
- data/lib/cyrax/presenter.rb +12 -12
- data/lib/cyrax/serializer.rb +3 -7
- data/lib/cyrax/serializers/scope.rb +12 -5
- data/lib/cyrax/version.rb +1 -1
- data/lib/cyrax/wrapper.rb +12 -0
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTk1NzA2YTkzMjQzMzQ4NTdlNzIxYWEzYzE3ZTFjY2Y3ZjIyNDE0NA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjA3NWY4YjNlMjRjNjU5Zjc2NDE2Zjc3MWRkZmRjMmMxNjUwNWU0Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjlkNjFjMTRjYjVhMzVhYTk4OTNhNmIzMDQ4OTk2NDMyZDI0ZjQ2MzlkYWVj
|
10
|
+
ZmVmMWUxNThlMWVhMGFmNDBhN2M4NzFmYTU0Mjk5MTEwZmMyZTNiMWRiNGYy
|
11
|
+
YTE1OTgxMzNiOWRjN2Y0ZmZlMGMxZWViMTc5Yzg1YmRkOWQzMzA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YzAwMjA4MWEwNzI3M2E1ZjgyNjllMGRlOWY3NWZkZjMwM2ViOWY5MDA2ZDZi
|
14
|
+
YmIxOGUwMWQ3NTc1Yjg2MjY2ZGY1YmZhOWMzNTljODI1NzlkZjI0MmEwOTI0
|
15
|
+
OGQwOWE2MzJiY2NlYjNhMDA1ZmQ5YjE2NDg4OWZjNzlkYzdhMzI=
|
data/lib/cyrax.rb
CHANGED
data/lib/cyrax/decorator.rb
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
require 'active_model'
|
2
|
-
class Cyrax::Decorator
|
2
|
+
class Cyrax::Decorator < Cyrax::Wrapper
|
3
3
|
include ActiveModel::Serialization
|
4
4
|
include ActiveModel::Serializers::JSON
|
5
5
|
include ActiveModel::Serializers::Xml
|
6
6
|
|
7
|
-
attr_accessor :resource
|
8
|
-
|
9
|
-
def initialize(resource)
|
10
|
-
@resource = resource
|
11
|
-
end
|
12
|
-
|
13
7
|
def to_model
|
14
8
|
resource
|
15
9
|
end
|
data/lib/cyrax/presenter.rb
CHANGED
@@ -1,34 +1,34 @@
|
|
1
|
-
class Cyrax::Presenter
|
2
|
-
def present
|
1
|
+
class Cyrax::Presenter < Cyrax::Wrapper
|
2
|
+
def present
|
3
3
|
should_decorate = options[:decorate].nil? || options[:decorate]
|
4
4
|
if options[:decorator] && should_decorate
|
5
|
-
present_with_decoration(
|
5
|
+
present_with_decoration(resource, options)
|
6
6
|
else
|
7
|
-
present_without_decoration(
|
7
|
+
present_without_decoration(resource, options)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
class << self
|
12
|
-
def present(
|
13
|
-
self.new
|
12
|
+
def present(resource, options = {})
|
13
|
+
self.new(resource, options).present
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def present_with_decoration(
|
19
|
+
def present_with_decoration(resource, options)
|
20
20
|
if options[:present] == :collection
|
21
|
-
Cyrax::Presenters::DecoratedCollection.new(
|
21
|
+
Cyrax::Presenters::DecoratedCollection.new(resource, options)
|
22
22
|
else
|
23
|
-
options[:decorator].decorate(
|
23
|
+
options[:decorator].decorate(resource)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
-
def present_without_decoration(
|
27
|
+
def present_without_decoration(resource, options)
|
28
28
|
if options[:present] == :collection
|
29
|
-
Cyrax::Presenters::BaseCollection.new(
|
29
|
+
Cyrax::Presenters::BaseCollection.new(resource, options)
|
30
30
|
else
|
31
|
-
|
31
|
+
resource
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/cyrax/serializer.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
class Cyrax::Serializer
|
2
|
-
attr_accessor :object
|
3
|
-
def initialize(object)
|
4
|
-
@object = object
|
5
|
-
end
|
6
|
-
|
1
|
+
class Cyrax::Serializer < Cyrax::Wrapper
|
7
2
|
def serialize
|
8
|
-
self
|
3
|
+
options[:serializer] = self
|
4
|
+
self.class.scope.serialize(resource, options)
|
9
5
|
end
|
10
6
|
|
11
7
|
class << self
|
@@ -2,6 +2,7 @@ module Cyrax::Serializers
|
|
2
2
|
class Scope
|
3
3
|
def initialize(&block)
|
4
4
|
@attrs = {}
|
5
|
+
@dynamic_attrs = {}
|
5
6
|
instance_eval(&block) if block_given?
|
6
7
|
end
|
7
8
|
|
@@ -15,20 +16,26 @@ module Cyrax::Serializers
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
def attribute(attribute, options = {})
|
19
|
-
|
20
|
-
|
19
|
+
def attribute(attribute, options = {}, &block)
|
20
|
+
if block_given?
|
21
|
+
@dynamic_attrs[attribute] = block
|
22
|
+
else
|
23
|
+
@attrs[attribute] = attribute
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
|
-
def serialize(
|
27
|
+
def serialize(resource, options = {})
|
24
28
|
result = {}
|
25
29
|
@attrs.map do |attribute, options|
|
26
|
-
value =
|
30
|
+
value = resource.send(attribute)
|
27
31
|
if options.is_a?(Cyrax::Serializers::Scope)
|
28
32
|
value = options.serialize(value)
|
29
33
|
end
|
30
34
|
result[attribute] = value
|
31
35
|
end
|
36
|
+
@dynamic_attrs.map do |attribute, block|
|
37
|
+
result[attribute] = options[:serializer].instance_eval(&block)
|
38
|
+
end
|
32
39
|
result
|
33
40
|
end
|
34
41
|
end
|
data/lib/cyrax/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
class Cyrax::Wrapper
|
2
|
+
include HasActiveLogger::Mixin
|
3
|
+
attr_accessor :resource
|
4
|
+
attr_accessor :options
|
5
|
+
attr_accessor :accessor
|
6
|
+
|
7
|
+
def initialize(resource = nil, options = {})
|
8
|
+
@resource = resource
|
9
|
+
@options = options
|
10
|
+
@accessor = options[:as]
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyrax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droidlabs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: has_active_logger
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '>='
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '>='
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Small library for adding service layer to Rails projects
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/cyrax/serializer.rb
|
91
91
|
- lib/cyrax/serializers/scope.rb
|
92
92
|
- lib/cyrax/version.rb
|
93
|
+
- lib/cyrax/wrapper.rb
|
93
94
|
- lib/cyrax.rb
|
94
95
|
- LICENSE.txt
|
95
96
|
- Rakefile
|
@@ -116,17 +117,17 @@ require_paths:
|
|
116
117
|
- lib
|
117
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
119
|
requirements:
|
119
|
-
- - '>='
|
120
|
+
- - ! '>='
|
120
121
|
- !ruby/object:Gem::Version
|
121
122
|
version: '0'
|
122
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
124
|
requirements:
|
124
|
-
- - '>='
|
125
|
+
- - ! '>='
|
125
126
|
- !ruby/object:Gem::Version
|
126
127
|
version: '0'
|
127
128
|
requirements: []
|
128
129
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.0.
|
130
|
+
rubygems_version: 2.0.5
|
130
131
|
signing_key:
|
131
132
|
specification_version: 4
|
132
133
|
summary: Small library for adding service layer to Rails projects
|