setting_accessors 0.1.0 → 0.2.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7caea2d742244efa6ea948761eab7f021f84496f
4
- data.tar.gz: 7926544739e71442d9ef609edc56261a027e1f70
3
+ metadata.gz: 7e10e1f1db74ffd1a88c6cda07070ee743347be2
4
+ data.tar.gz: bb11685605adb3eb565543d9282b76c133609529
5
5
  SHA512:
6
- metadata.gz: 3994281b120a84ae882f203c14e45a6cc71ef08ba5a8e4206c17088018a8d8349e8dfda5938b2269aaca2a4efbc06377390893f39bb98b1a798cebed5617bfe9
7
- data.tar.gz: 21a739c4597006df8cf6b6d86ed959824501cd4fb3e83d015bbd43f51cd83f93a3b9f1316a8794ffaff793d5440c5d5a250dd3ee5d585578a2692d24e5a1dc8a
6
+ metadata.gz: 4cf233138c9ea194ce51cf154a136030ef7d835fa089f968d2ba6ffdd47b33b191357496e6627a3f56b3d4d9713e678b922d34e6843249f92f859d5c12c9b1c2
7
+ data.tar.gz: df955321287251309b6a5f2ef6dd24e0701b3218423eb365dbf5e5156e4cea031526fa6ce3b5478b9b69dda030f9067807331d34888dcce2363cacf34a8c0c90
@@ -104,9 +104,17 @@ module SettingAccessors::Integration
104
104
  self
105
105
  end
106
106
 
107
- def as_json(*)
108
- json = super
109
- SettingAccessors::Internal.setting_accessor_names(self.class).each do |setting_name|
107
+ def as_json(options = {})
108
+ json = super options
109
+
110
+ setting_names = SettingAccessors::Internal.setting_accessor_names(self.class)
111
+ if only = options[:only]
112
+ setting_names &= Array(only).map(&:to_s)
113
+ elsif except = options[:except]
114
+ setting_names -= Array(except).map(&:to_s)
115
+ end
116
+
117
+ setting_names.each do |setting_name|
110
118
  json[setting_name.to_s] = send(setting_name)
111
119
  end
112
120
  json
@@ -1,3 +1,3 @@
1
1
  module SettingAccessors
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
Binary file
@@ -17,6 +17,48 @@ class UserTest < ActiveSupport::TestCase
17
17
  assert_equal @user.as_json[setting_name.to_s], @user.send(setting_name)
18
18
  end
19
19
  end
20
+
21
+ context 'when using as_json with option :only' do
22
+ context 'set to a class attribute name' do
23
+ should 'not include any setting accessors' do
24
+ json = @user.as_json :only => [:first_name]
25
+ SettingAccessors::Internal.setting_accessor_names(User).each do |setting_name|
26
+ assert_not_includes json.keys, setting_name
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'set to a setting accessor name' do
32
+ should 'not include other setting accessors' do
33
+ json = @user.as_json :only => [:a_string]
34
+ assert_includes json.keys, 'a_string'
35
+ (SettingAccessors::Internal.setting_accessor_names(User) - ['a_string']).each do |setting_name|
36
+ assert_not_includes json.keys, setting_name
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ context 'when using as_json with option :except' do
43
+ context 'set to a class attribute name' do
44
+ should 'include all setting accessors' do
45
+ json = @user.as_json :except => [:first_name]
46
+ SettingAccessors::Internal.setting_accessor_names(User).each do |setting_name|
47
+ assert_includes json.keys, setting_name
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'set to a setting accessor name' do
53
+ should 'include all other setting accessors' do
54
+ json = @user.as_json :except => [:a_string]
55
+ assert_not_includes json.keys, 'a_string'
56
+ (SettingAccessors::Internal.setting_accessor_names(User) - ['a_string']).each do |setting_name|
57
+ assert_includes json.keys, setting_name
58
+ end
59
+ end
60
+ end
61
+ end
20
62
  end
21
63
 
22
64
  context 'Boolean getter methods' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: setting_accessors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Exner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-20 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
224
  version: '0'
225
225
  requirements: []
226
226
  rubyforge_project:
227
- rubygems_version: 2.5.1
227
+ rubygems_version: 2.6.9
228
228
  signing_key:
229
229
  specification_version: 4
230
230
  summary: A global key-value-store and virtual model columns