cyrax 0.2.7 → 0.2.8
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 +8 -8
- data/lib/cyrax.rb +2 -1
- data/lib/cyrax/base_collection_presenter.rb +15 -0
- data/lib/cyrax/base_presenter.rb +10 -2
- data/lib/cyrax/{collection_decorator.rb → decorated_collection_presenter.rb} +3 -13
- data/lib/cyrax/decorator.rb +1 -1
- data/lib/cyrax/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDI3MGJhMmRlYWU5ZjNmNDQyNDFlNmZmODczMjQ4ZmQ5ODc3MmQ3Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjZkMWRiMDlmNTQ5YmNhZDk1MjI2NThiMGFkMGIwODBhOTljYjI4Yw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTYwMWI1NTE4Y2M5NjkxMjA4OTI3ZDE4NzNjZDg4OTMxOTJlNjBkZjdiNTZl
|
10
|
+
M2Y5N2IwNmEyM2YxMmZhMTYzM2ZhMTRmMGMxMTVlYjI5OTI2MWQ0YmQ2ZjQ0
|
11
|
+
ODhmNWUzNTRlOWRjZGE3NDc3Njk2ZTA0YWRmYzEzMzQzNmE5NTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTc0ZDhkMmIyZDkzMDBhYWQ4NzI1ODkxNGE5ZDE0MTgzNTgzNmVlMGRjZGUy
|
14
|
+
YjRmYzhlMGIwMGQzNGE0Mjk2ZWY4OGFjMThhZGVjZjIwNDc1YTU2N2UzOTFj
|
15
|
+
ODA1OGQzOTU4YTE2MWM5N2YyNzBhZWIxYmQ5MDIzNzMzZGIxMjQ=
|
data/lib/cyrax.rb
CHANGED
@@ -9,7 +9,8 @@ require "cyrax/base_resource.rb"
|
|
9
9
|
require "cyrax/base_presenter.rb"
|
10
10
|
require "cyrax/response.rb"
|
11
11
|
require "cyrax/callbacks.rb"
|
12
|
-
require "cyrax/
|
12
|
+
require "cyrax/base_collection_presenter.rb"
|
13
|
+
require "cyrax/decorated_collection_presenter.rb"
|
13
14
|
require "cyrax/decorator.rb"
|
14
15
|
|
15
16
|
module Cyrax
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Cyrax::BaseCollectionPresenter
|
2
|
+
def initialize(collection, options = {})
|
3
|
+
@collection = collection
|
4
|
+
end
|
5
|
+
|
6
|
+
def fetched_collection
|
7
|
+
if collection.is_a?(ActiveRecord::Relation)
|
8
|
+
collection.to_a
|
9
|
+
elsif collection.respond_to?(:all)
|
10
|
+
collection.all
|
11
|
+
else
|
12
|
+
Array.wrap collection
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/cyrax/base_presenter.rb
CHANGED
@@ -5,7 +5,7 @@ class Cyrax::BasePresenter
|
|
5
5
|
if options[:decorable] && should_decorate
|
6
6
|
present_with_decoration(object, options)
|
7
7
|
else
|
8
|
-
object
|
8
|
+
present_without_decoration(object, options)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -18,10 +18,18 @@ class Cyrax::BasePresenter
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def present_with_decoration(object, options)
|
21
|
-
if options[:present] == :collection
|
21
|
+
if options[:present] == :collection
|
22
22
|
options[:decorator_class].decorate_collection(object)
|
23
23
|
else
|
24
24
|
options[:decorator_class].decorate(object)
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
def present_without_decoration(object, options)
|
29
|
+
if options[:present] == :collection
|
30
|
+
Cyrax::BaseCollectionPresenter.new(object).fetched_collection
|
31
|
+
else
|
32
|
+
object
|
33
|
+
end
|
34
|
+
end
|
27
35
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
class Cyrax::
|
2
|
-
attr_reader :decorator_class
|
1
|
+
class Cyrax::DecoratedCollectionPresenter < Cyrax::BaseCollectionPresenter
|
2
|
+
attr_reader :decorator_class
|
3
3
|
|
4
4
|
def initialize(collection, options = {})
|
5
|
-
|
5
|
+
super
|
6
6
|
@decorator_class = options[:decorator_class]
|
7
7
|
raise "Decorator class is not defined! Please define it with option :decorator_class" unless decorator_class
|
8
8
|
end
|
@@ -18,16 +18,6 @@ class Cyrax::CollectionDecorator
|
|
18
18
|
@decorated_collection ||= fetched_collection.map {|item| decorate_item(item)}
|
19
19
|
end
|
20
20
|
|
21
|
-
def fetched_collection
|
22
|
-
if collection.is_a?(ActiveRecord::Relation)
|
23
|
-
collection.to_a
|
24
|
-
elsif collection.respond_to?(:all)
|
25
|
-
collection.all
|
26
|
-
else
|
27
|
-
Array.wrap collection
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
21
|
def method_missing(method, *args, &block)
|
32
22
|
return super unless collection.respond_to?(method)
|
33
23
|
collection.send(method, *args, &block)
|
data/lib/cyrax/decorator.rb
CHANGED
@@ -31,7 +31,7 @@ class Cyrax::Decorator
|
|
31
31
|
alias_method :decorate, :new
|
32
32
|
|
33
33
|
def decorate_collection(resource)
|
34
|
-
Cyrax::
|
34
|
+
Cyrax::DecoratedCollectionPresenter.decorate(resource, decorator_class: self)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/cyrax/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyrax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droidlabs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -73,10 +73,11 @@ extensions: []
|
|
73
73
|
extra_rdoc_files: []
|
74
74
|
files:
|
75
75
|
- lib/cyrax/base.rb
|
76
|
+
- lib/cyrax/base_collection_presenter.rb
|
76
77
|
- lib/cyrax/base_presenter.rb
|
77
78
|
- lib/cyrax/base_resource.rb
|
78
79
|
- lib/cyrax/callbacks.rb
|
79
|
-
- lib/cyrax/
|
80
|
+
- lib/cyrax/decorated_collection_presenter.rb
|
80
81
|
- lib/cyrax/decorator.rb
|
81
82
|
- lib/cyrax/extensions/has_callbacks.rb
|
82
83
|
- lib/cyrax/extensions/has_decorator.rb
|