cyrax 0.7.0 → 0.7.1

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGI2YjFjYzU3ZDA4OGJlOTNjMWQzNjcxMDMwMzYzODM3ZmRhNTVhNQ==
4
+ NmVmYTYxMjdjYjFjNzQ3NDZlMmY1NTU4MzNlNjE0ZDE2MzYyMTA1Mg==
5
5
  data.tar.gz: !binary |-
6
- ZDZjNzE5ZTM2NTAxMjI2MjllOWIyOWQ5NDk4NTQ5ZWNhYTBiYWRlZA==
6
+ NWFlM2YxZWI2Y2FjODRhNWVjYzg0ZTIyNDgyOGM4MWMzMTAyZGI4Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjZmOTc3OWE5MWExZmEyYmMyMTkwNGUxNDNmYzZmZjEzMTU0NWVjMTEyNTQ5
10
- NmZkMDQxZDI1YWMxMTIyMjhhMTFlODZlZjJiYjhjMmFjYTc4YzNjZDE1MGNh
11
- YjA4OWRiZDhiYWEzZGM0Mjc2NGVkYTNlNGM1ZjA4MjIxMWYyMDM=
9
+ NTExZjYzODQwYjgwYjNjNTY4MTQzNzNkOTMzMjQ4NjA1ZTZmNmFhYWVkYjBm
10
+ Y2FmOGU2ZGFjZTljNDdjOGI4NmI1MTg2YzhhZmZlMjJiNmQyZGIwM2YwYTA1
11
+ ZTcyYzRmNDEzOGRkZDIzYTIxYTg5NmUwZjY1MjRkYzVhMzdhMWI=
12
12
  data.tar.gz: !binary |-
13
- ZTQ5YWM4NTczOTk2N2M0YzUzZDUwMWMyNWRjZmIxZDUwYWRiMzI2YzNmZjZi
14
- Yzg4ZWNjYjVjYjA1YTE4NDY4OTk5YjZiMzk1NDczYWQ5ODc3NTJhY2I0YWRj
15
- ZTZiNjAyMWYxOTRjNjE2MTIyOGIyNDIzMzg3NDYzYzNmNWFmOTM=
13
+ MGNiNjhjODJmMzk1M2RkNDlkOTBkYzE3OTk1NmE4YjBhODBiYmIyNjRlNmM4
14
+ OWU2YzYyNmE4NTViZTBmMGUxNzFkYWZlYjljODllZDU4OTUzNDRlMmJkZjI5
15
+ MTRjYjk2MTUxNGRkOGRlZjZkMzllNmFiYzBlODZjMWJiYTFhNTg=
@@ -82,6 +82,7 @@ module Cyrax::Extensions
82
82
  # @param options [Hash] Options
83
83
  def respond_with(result, options = {})
84
84
  options[:as] ||= accessor
85
+ options[:assignments] = @_assignments
85
86
  name = options[:name] || response_name
86
87
  result = result.result.to_model if result.is_a?(Cyrax::Response)
87
88
  if sync_errors_with?(result)
@@ -55,7 +55,7 @@ class Cyrax::Response
55
55
  if failure?
56
56
  {errors: @errors}
57
57
  elsif options[:serializer]
58
- options[:serializer].new(result, as: accessor).serialize
58
+ options[:serializer].new(result, options).serialize
59
59
  else
60
60
  result.as_json
61
61
  end
@@ -13,6 +13,10 @@ class Cyrax::Serializer < Cyrax::Wrapper
13
13
  scope.namespace(name, &block)
14
14
  end
15
15
 
16
+ def assigned(name, &block)
17
+ scope.assigned(name, &block)
18
+ end
19
+
16
20
  def relation(name, &block)
17
21
  scope.relation(name, &block)
18
22
  end
@@ -5,6 +5,7 @@ module Cyrax::Serializers
5
5
  @dynamic_attrs = {}
6
6
  @relation_attrs = {}
7
7
  @namespace_attrs = {}
8
+ @assigned_attrs = {}
8
9
  @default_attributes = false
9
10
  instance_eval(&block) if block_given?
10
11
  end
@@ -13,6 +14,10 @@ module Cyrax::Serializers
13
14
  @namespace_attrs[name] = self.class.new(&block)
14
15
  end
15
16
 
17
+ def assigned(name, &block)
18
+ @assigned_attrs[name] = self.class.new(&block)
19
+ end
20
+
16
21
  def relation(attribute, &block)
17
22
  if block_given?
18
23
  @relation_attrs[attribute] = self.class.new(&block)
@@ -20,6 +25,8 @@ module Cyrax::Serializers
20
25
  @attrs[attribute] = attribute
21
26
  end
22
27
  end
28
+ alias_method :has_many, :relation
29
+ alias_method :has_one, :relation
23
30
 
24
31
  def default_attributes
25
32
  @default_attributes = true
@@ -62,6 +69,10 @@ module Cyrax::Serializers
62
69
  @namespace_attrs.map do |attribute, scope|
63
70
  result[attribute] = scope.serialize(resource)
64
71
  end
72
+ @assigned_attrs.map do |attribute, scope|
73
+ value = options[:assignments][attribute]
74
+ result[attribute] = scope.serialize(value)
75
+ end
65
76
  @attrs.map do |attribute, options|
66
77
  result[attribute] = resource.send(attribute)
67
78
  end
data/lib/cyrax/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cyrax
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -59,7 +59,7 @@ module Cyrax
59
59
  describe '#respond_with' do
60
60
  before { subject.stub(:response_name).and_return(:foo) }
61
61
  it 'calls Cyrax::Response' do
62
- Cyrax::Response.should_receive(:new).with(:foo, 'bar', {as: nil}).and_return(double.as_null_object)
62
+ Cyrax::Response.should_receive(:new).with(:foo, 'bar', {as: nil, assignments: nil}).and_return(double.as_null_object)
63
63
  subject.respond_with('bar')
64
64
  end
65
65
 
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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Droidlabs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-18 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport