rep 0.9.1 → 0.9.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: c17bcaee77e4f9ffbd8f683f5b683535e665709d
4
- data.tar.gz: b680fed0d66c62d850373c1bbbd1050dba41509f
3
+ metadata.gz: e03566cf648d2e0c00bf8a7a49bc5c4582e74bfb
4
+ data.tar.gz: e5388c2277d0766bc1243d80453a2f1a4b2944f5
5
5
  SHA512:
6
- metadata.gz: 432af63b976a0a3df373a3c2492053812de1613ea4388ceedefceb94a078eed98f70492dac27cd9853cfb50a25beed8e0d99dcf918d22b341bf02f3061cdacfd
7
- data.tar.gz: 952529dce714713badc0bd3d2ba8c100e9898aebdaa69df518d4193a89e0851cbd6529d7c9f8ecaff319bf224ccd9f731a4181ecef9c2ff1ef59957d394d018e
6
+ metadata.gz: 03ef5a4f5ac3ea25c64a7d043c696b8b7d77db296cab3c6f498f25d80cff5a892322a54de721d8fd3050860e43ad9f0129cb90e9fe7dbd772a612d994d083584
7
+ data.tar.gz: cd1175b6ba8977db0e456a5b671643998682a0f8ff058901357d424f7cc89ea5506a4aa34eac2d7c5a5b1d2399e199ff6d0bd233209d7857d3449b462e2c11e1
data/lib/rep.rb CHANGED
@@ -71,7 +71,18 @@ module Rep
71
71
  # if there are no json fields setup for the particular set (which defaults to `:default`).
72
72
 
73
73
  def to_hash(name = :default)
74
- if fields = self.class.json_fields(name)
74
+ fields = if name.is_a?(Hash)
75
+ hash = name
76
+ if hash.keys.include?(:fields)
77
+ fields = hash[:fields]
78
+ else
79
+ raise "Argument must be either `fields: [...]` or `:symbol`"
80
+ end
81
+ else
82
+ self.class.json_fields(name)
83
+ end
84
+
85
+ if fields
75
86
  fields.each_with_object({}) do |field, memo|
76
87
  field_name, method_name = field.is_a?(Hash) ? field.to_a.first : [field, field]
77
88
  if self.respond_to?(method_name)
@@ -1,3 +1,3 @@
1
1
  module Rep
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -94,6 +94,16 @@ describe Rep do
94
94
  klass.new.to_hash.must_equal :one => 1, :two => 2, :three => 3
95
95
  end
96
96
 
97
+ it "should allow a fields override in to_hash" do
98
+ klass = new_rep_class do
99
+ fields [:one, :two, :three] => :default
100
+ def one; 1; end
101
+ def two; raise("shouldn't call me at all"); end
102
+ def three; 3; end
103
+ end
104
+ klass.new.to_hash(fields: [:one, :three]).must_equal :one => 1, :three => 3
105
+ end
106
+
97
107
  it "should send fields to instance to make json" do
98
108
  klass = new_rep_class do
99
109
  fields [:one, :two, :three] => :default
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - myobie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-24 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: mashed
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.9.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.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
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: :development
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: minitest
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: :development
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
  description: A library for writing authoritative representations of objects for pages
@@ -60,8 +60,8 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - .gitignore
64
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -93,17 +93,17 @@ require_paths:
93
93
  - lib
94
94
  required_ruby_version: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.0.2
106
+ rubygems_version: 2.2.2
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Include Rep into any object to endow it to create json (or hashes) easily.