restpack_serializer 0.2.5 → 0.2.6

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
- YmViZmMyYTk0YTVhZDY0YTczMGQ4MDIwMThjZjNhMDBhZmFmMWZlOA==
4
+ ZWM1YTg1ZWIyMWJmNjFlNDgyMTY0YWRkN2JkMzdiMzIyMTNkOTY3MQ==
5
5
  data.tar.gz: !binary |-
6
- YmEzNGY0ZDU2Y2Y3ZTI1OTkyNzBhYmVhMmU0NzIxNGRjYmJjNTNmYg==
6
+ ODQ4NTZjYzljZDBjNjllNjAyOGFlYzA1YjM5ODgwMzM3YjczODlhYQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YjMyYTgyOWJmZTc4NDBlYmY4OGZiMDljMzFlZjQ0ZTM5MmYzNjUwMjkxZWVj
10
- ZWE0YjNhMjUzYzlmYTBlZmQ5OWNlYjBiMmY5NzRkNTI0MDg5MTNhMmZmNWM3
11
- NGI1OWFkOWRhZTU3YzZkOWQ2N2JlNWVjMGNjMjhiYzVhMjQ2MjQ=
9
+ MzRlMGQzOWFkMmRjYzI0Y2VmZDk0NTcyMzc4NTllOTM2ODk5OGU5MGJlZGFi
10
+ OTQ1MGQxNDIwMDdkZDQ1MzEyNWMwMWQyYjE2NmMwMDRhOGE3MWE5N2JhOTVh
11
+ ZGI1M2VjOTc4NmQ1ODJhMjU0YmY3YzlmMzY1N2E3OWIwZGRjNTY=
12
12
  data.tar.gz: !binary |-
13
- YTRlMGZkMTAwZjM1YzZhODI4NjdmNGIwMTdhMzY2YTcwZDg4NjAyNWM2MmYy
14
- ODEzMTUyNTEzOTkwZmQ5MzE4OGUwOTFlNzZjZmRiNDlmN2Y1YjIwMzUxODM3
15
- Y2ZiZTJkNjgyOTA1ZWI2NjAxODk4MzZiZDVhZDk0NTY0ZDQ2MDg=
13
+ ODBlYzFkNDJiYjIxODk1OThhMTM5YWVlOTgwZGViZDBkMDIzMjJhOWVjNTk0
14
+ ODNmZWU1NWJmYWU3MGY3MmUyMDQzMjkwN2RmNDk0NWJiMDZlZjUyMGM4MzQ5
15
+ ZDE3ZGNhNGQ5Mjk3ZWU0YWY4ZjdhNzY2NjkwMDFiMTM3MDhjNWI=
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- restpack_serializer (0.2.5)
4
+ restpack_serializer (0.2.6)
5
5
  activerecord (>= 3.0)
6
6
  activesupport (>= 3.0)
7
7
  will_paginate (~> 3.0)
@@ -1,6 +1,12 @@
1
1
  module RestPack::Serializer::Attributes
2
2
  extend ActiveSupport::Concern
3
3
 
4
+ module InstanceMethods
5
+ def default_href
6
+ "#{RestPack::Serializer.href_prefix}/#{@model.class.table_name}/#{@model.id}.json"
7
+ end
8
+ end
9
+
4
10
  module ClassMethods
5
11
  def serializable_attributes
6
12
  @serializable_attributes
@@ -23,7 +29,8 @@ module RestPack::Serializer::Attributes
23
29
  def define_attribute_method(name)
24
30
  unless method_defined?(name)
25
31
  define_method name do
26
- value = @model.send(name)
32
+ value = self.default_href if name == :href
33
+ value ||= @model.send(name)
27
34
  value = value.to_s if name == :id
28
35
  value
29
36
  end
@@ -1,5 +1,5 @@
1
1
  module RestPack
2
2
  module Serializer
3
- VERSION = '0.2.5'
3
+ VERSION = '0.2.6'
4
4
  end
5
5
  end
@@ -29,10 +29,10 @@ describe RestPack::Serializer do
29
29
 
30
30
  class PersonSerializer
31
31
  include RestPack::Serializer
32
- attributes :id, :name, :url, :admin_info
32
+ attributes :id, :name, :description, :href, :admin_info
33
33
 
34
- def url
35
- "/api/v1/people/#{id}.json"
34
+ def description
35
+ "This is person ##{id}"
36
36
  end
37
37
 
38
38
  def admin_info
@@ -47,14 +47,14 @@ describe RestPack::Serializer do
47
47
  describe ".as_json" do
48
48
  it "serializes specified attributes" do
49
49
  serializer.as_json(person).should == {
50
- id: '123', name: 'Gavin', url: '/api/v1/people/123.json'
50
+ id: '123', name: 'Gavin', description: 'This is person #123', href: '/people/123.json'
51
51
  }
52
52
  end
53
53
 
54
54
  context "with options" do
55
55
  it "excludes specified attributes" do
56
- serializer.as_json(person, { include_url?: false }).should == {
57
- id: '123', name: 'Gavin'
56
+ serializer.as_json(person, { include_description?: false }).should == {
57
+ id: '123', name: 'Gavin', href: '/people/123.json'
58
58
  }
59
59
  end
60
60
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restpack_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Joyce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-19 00:00:00.000000000 Z
11
+ date: 2013-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord