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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c6cb52988ca75e1ff0e42e4ead186b615bf182ee
4
- data.tar.gz: fb57424b1ace91f230b73e1b2ff421ab26666120
5
- SHA512:
6
- metadata.gz: 388e384b6b586fdbc4dfd55a8e9ae3380bad03b117a2242cce4828754bf63c3e3fa70a45f842900afda5f4efdaf869b25cd5ec7a5f71b1cdcc64797b10355b9f
7
- data.tar.gz: cfc4d56f3c587efe4e25fda2616255c45b23ac84d67266a52f8ae4585fb2fb9311b7d9d5a33d2c12cabab3e16b8f4deaa255e08389c7003865ad3b257cb7d36c
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
@@ -11,6 +11,7 @@ require "cyrax/serializers/scope.rb"
11
11
  require "cyrax/helpers/controller.rb"
12
12
  require "cyrax/base.rb"
13
13
  require "cyrax/resource.rb"
14
+ require "cyrax/wrapper.rb"
14
15
  require "cyrax/presenter.rb"
15
16
  require "cyrax/response.rb"
16
17
  require "cyrax/callbacks.rb"
@@ -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
@@ -37,6 +37,7 @@ module Cyrax::Extensions
37
37
  end
38
38
 
39
39
  def respond_with(result, options = {})
40
+ options[:as] ||= accessor
40
41
  name = options[:name] || response_name
41
42
  result = result.result.to_model if result.is_a?(Cyrax::Response)
42
43
  if respond_to?(:decorable?) && decorable?
@@ -1,34 +1,34 @@
1
- class Cyrax::Presenter
2
- def present(object, options = {})
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(object, options)
5
+ present_with_decoration(resource, options)
6
6
  else
7
- present_without_decoration(object, options)
7
+ present_without_decoration(resource, options)
8
8
  end
9
9
  end
10
10
 
11
11
  class << self
12
- def present(object, options = {})
13
- self.new.present(object, options)
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(object, options)
19
+ def present_with_decoration(resource, options)
20
20
  if options[:present] == :collection
21
- Cyrax::Presenters::DecoratedCollection.new(object, options)
21
+ Cyrax::Presenters::DecoratedCollection.new(resource, options)
22
22
  else
23
- options[:decorator].decorate(object)
23
+ options[:decorator].decorate(resource)
24
24
  end
25
25
  end
26
26
 
27
- def present_without_decoration(object, options)
27
+ def present_without_decoration(resource, options)
28
28
  if options[:present] == :collection
29
- Cyrax::Presenters::BaseCollection.new(object, options)
29
+ Cyrax::Presenters::BaseCollection.new(resource, options)
30
30
  else
31
- object
31
+ resource
32
32
  end
33
33
  end
34
34
  end
@@ -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.class.scope.serialize(object)
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
- @attrs ||= {}
20
- @attrs[attribute] ||= attribute
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(object)
27
+ def serialize(resource, options = {})
24
28
  result = {}
25
29
  @attrs.map do |attribute, options|
26
- value = object.send(attribute)
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
@@ -1,3 +1,3 @@
1
1
  module Cyrax
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -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.2
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-05 00:00:00.000000000 Z
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.6
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