jsonapi-serializable 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb3b603af78361747fc5ff33c1a81c19c66a78af
4
- data.tar.gz: 8113fbfcbc52ff590bf7b820dbee01fa43b37b8b
3
+ metadata.gz: 4cb44ca89eb1b7e4d57963e58ee633a72286bf09
4
+ data.tar.gz: b58ecc0baa551e82c9a3d4de80d197d779c0c31b
5
5
  SHA512:
6
- metadata.gz: 54f95566a246044b529b017fd7bf38da736ece3332ee79d221752221baf9840f3ae26d1482061dfce323775fed052fee98bcc879e65e583a6a3943f70dcfa4a7
7
- data.tar.gz: f9557913f0fa0ee5fa6c35212fdb193ffc2bae554205e988039de7f80ecdf1a3e3c8e9c85d740f9922e85d06e69c1cb51559834e3166e2005142caca0e2d42b7
6
+ metadata.gz: 665e7c08b7c03d91db56c6bcf89d592e84618b6b8d00f41defb42c3cd42412938366d4e010c7cbd1d2680f70b24c1cd4377d9dfc5e7b06d6f78c292d22774de9
7
+ data.tar.gz: 4947189e22b7ea602475972030cdf332230a311a1f86289a44de542cb73bcbcbcfcc02ce01e42049fbba3eca72ce546f9dc80b4f63167a5ce11cacb098cf06dc
data/README.md CHANGED
@@ -8,6 +8,12 @@ Ruby gem for building and rendering [JSON API](http://jsonapi.org) documents.
8
8
  [![codecov](https://codecov.io/gh/jsonapi-rb/jsonapi-serializable/branch/master/graph/badge.svg)](https://codecov.io/gh/jsonapi-rb/jsonapi-serializable)
9
9
  [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/jsonapi-rb/Lobby)
10
10
 
11
+ ## Resources
12
+
13
+ * Chat: [gitter](http://gitter.im/jsonapi-rb)
14
+ * Twitter: [@jsonapirb](http://twitter.com/jsonapirb)
15
+ * Docs: [jsonapi-rb.org](http://jsonapi-rb.org)
16
+
11
17
  ## Installation
12
18
  ```ruby
13
19
  # In Gemfile
@@ -20,7 +20,6 @@ module JSONAPI
20
20
 
21
21
  private
22
22
 
23
- # @api private
24
23
  def method_missing(name, arg)
25
24
  @_data[name] = arg
26
25
  end
@@ -4,7 +4,7 @@ require 'jsonapi/serializable/resource_builder'
4
4
  module JSONAPI
5
5
  module Serializable
6
6
  class Renderer
7
- def self.render(objects, options)
7
+ def self.render(objects, options = {})
8
8
  new(objects, options).render
9
9
  end
10
10
 
@@ -14,7 +14,7 @@ module JSONAPI
14
14
  module ConditionalFields
15
15
  def self.prepended(klass)
16
16
  klass.class_eval do
17
- extend ClassMethods
17
+ extend DSL
18
18
  class << self
19
19
  attr_accessor :condition_blocks
20
20
  end
@@ -23,7 +23,7 @@ module JSONAPI
23
23
  end
24
24
 
25
25
  # DSL extensions for conditional fields.
26
- module ClassMethods
26
+ module DSL
27
27
  def inherited(klass)
28
28
  super
29
29
  klass.condition_blocks = condition_blocks.dup
@@ -13,27 +13,27 @@ module JSONAPI
13
13
  # has_many :close_friends
14
14
  # end
15
15
  # # => will modify the serialized keys to `UserName` and `CloseFriends`.
16
- module KeyTransform
16
+ module KeyFormat
17
17
  def self.prepended(klass)
18
18
  klass.class_eval do
19
- extend ClassMethods
19
+ extend DSL
20
20
  class << self
21
- attr_accessor :key_transform
21
+ attr_accessor :key_format
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
26
  # DSL extensions for automatic key transformations.
27
- module ClassMethods
27
+ module DSL
28
28
  def inherited(klass)
29
29
  super
30
- klass.key_transform = key_transform
30
+ klass.key_format = key_format
31
31
  end
32
32
 
33
33
  # Handles automatic key transformation for attributes.
34
34
  def attribute(name, options = {}, &block)
35
35
  block ||= proc { @object.public_send(name) }
36
- super(key_transform.call(name), options, &block)
36
+ super(key_format.call(name), options, &block)
37
37
  end
38
38
 
39
39
  # Handles automatic key transformation for relationships.
@@ -42,7 +42,7 @@ module JSONAPI
42
42
  data(options[:class]) { @object.public_send(name) }
43
43
  instance_eval(&block) unless block.nil?
44
44
  end
45
- super(key_transform.call(name), options, &rel_block)
45
+ super(key_format.call(name), options, &rel_block)
46
46
  end
47
47
  end
48
48
  end
@@ -8,14 +8,18 @@ module JSONAPI
8
8
  klass.class_eval do
9
9
  extend DSL
10
10
  class << self
11
- attr_accessor :type_val
11
+ attr_accessor :type_val, :type_block
12
12
  end
13
13
  end
14
14
  end
15
15
 
16
16
  def initialize(*)
17
17
  super
18
- @_type = self.class.type_val || :unknown
18
+ @_type = if self.class.type_block
19
+ instance_eval(&self.class.type_block).to_sym
20
+ else
21
+ self.class.type_val || :unknown
22
+ end
19
23
  end
20
24
 
21
25
  # @see JSONAPI::Serializable::Resource#as_jsonapi
@@ -29,16 +33,27 @@ module JSONAPI
29
33
  module DSL
30
34
  def inherited(klass)
31
35
  super
32
- klass.type_val = type_val
36
+ klass.type_val = type_val
37
+ klass.type_block = type_block
33
38
  end
34
39
 
35
- # Declare the JSON API type of this resource.
36
- # @param [String] value The value of the type.
40
+ # @overload type(value)
41
+ # Declare the JSON API type of this resource.
42
+ # @param [String] value The value of the type.
37
43
  #
38
- # @example
39
- # type 'users'
40
- def type(value)
41
- self.type_val = value.to_sym
44
+ # @example
45
+ # type 'users'
46
+ #
47
+ # @overload type(&block)
48
+ # Declare the JSON API type of this resource.
49
+ # @yieldreturn [String] The value of the type.
50
+ # @example
51
+ # type do
52
+ # @object.type
53
+ # end
54
+ def type(value = nil, &block)
55
+ self.type_val = value.to_sym if value
56
+ self.type_block = block
42
57
  end
43
58
  end
44
59
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-serializable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Hosseini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-02 00:00:00.000000000 Z
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-renderer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.1
19
+ version: '0.1'
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
- version: 0.1.1
26
+ version: '0.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ files:
85
85
  - lib/jsonapi/serializable/resource/attributes.rb
86
86
  - lib/jsonapi/serializable/resource/conditional_fields.rb
87
87
  - lib/jsonapi/serializable/resource/id.rb
88
- - lib/jsonapi/serializable/resource/key_transform.rb
88
+ - lib/jsonapi/serializable/resource/key_format.rb
89
89
  - lib/jsonapi/serializable/resource/links.rb
90
90
  - lib/jsonapi/serializable/resource/meta.rb
91
91
  - lib/jsonapi/serializable/resource/relationships.rb