cyrax 0.5.2 → 0.5.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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjFlNjRkMDcxZjQ4NDZhNjA1YzllYTczNzU0YjUyM2NiMThkMDIwYg==
4
+ NmIyODJjMDljMjllMmJkNzM0YmM4ZTY3ZDE5OGFjMTBhYjZjZTRkNQ==
5
5
  data.tar.gz: !binary |-
6
- MjcwMjAwMWFkM2U3MmI2ZWU1NGExNjE5MDRiNmQ0MDg3YTM3MzM5Nw==
6
+ MjU3NTYzNWU4NGMwNWJlYjNiYjFkOTRmNzM1YjUxMjgyN2E3YTcxNw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZGNlMDIwYzVmMTZjMzEwMzMwNTU5OGQ0YTY5YjZmMDczMGExZjg3ZWEzY2Fl
10
- M2E0ODIyMDAyODc3NTY1ODQwMTc5MGMzODdhYjNmMzljMGY0YzU5YTVhMDBh
11
- MmE4MmUwMDllMTg3ZWM1ZDBkMzkwNTEzYWU5NTE3N2Y3NjNhNGE=
9
+ MjYzNWRkNDlhMGRkN2YyOWU3NzlkYjI3YWFkNmVmYmRmNTRiNzY2NTQzZTIx
10
+ Y2E1OTJmMWI4NTUwMzBkYzg4YmM4NDgyZGNkMjk2YTEwOWE3MDM5NDhjNmIy
11
+ YmRhZTVjZDdkYTljZTQ3Njc3OWM3MmNlOGM5NDhiZDllMDllYTg=
12
12
  data.tar.gz: !binary |-
13
- ODkxM2RmNWQ4ZGZlZGNjNWYwZDEwN2FkOTJmY2RhNDhkNTVjOTk3M2VkODRk
14
- OGQxNDFjMzJmZjI3NzdlM2Y0ZjBmNGY2MDk5YTA5MjBkYWU0ZTZlOTBjMDkx
15
- MjI2MTZhODExNDFmYjg0MGUxYjNkZWU0ZWI5YWM2OTVhNzVlNWU=
13
+ N2Q2MjYyYzViNjljM2I4ZWYyZjYwYTM5ZDNhMjZjNjk4YWJjMmVlODAwMDRj
14
+ N2RjZmE1ZGQwMjcyNDBiNWY3MWU3ZDQzODI3YTZkNjliMTdhYTMxMTVjMjQ5
15
+ NjFlZGZiNGQ1ODM3OWViN2QxNmNlODQyMmZmZTllODc4MmE4MTA=
@@ -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
@@ -59,6 +66,10 @@ module Cyrax::Serializers
59
66
  value = resource.send(attribute)
60
67
  result[attribute] = scope.serialize(value)
61
68
  end
69
+ @assigned_attrs.map do |attribute, scope|
70
+ value = options[:assignments][attribute]
71
+ result[attribute] = scope.serialize(value)
72
+ end
62
73
  @namespace_attrs.map do |attribute, scope|
63
74
  result[attribute] = scope.serialize(resource)
64
75
  end
data/lib/cyrax/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cyrax
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
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.5.2
4
+ version: 0.5.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-12-07 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
@@ -152,3 +152,4 @@ test_files:
152
152
  - spec/cyrax/response_spec.rb
153
153
  - spec/cyrax/serializer_spec.rb
154
154
  - spec/spec_helper.rb
155
+ has_rdoc: