remote_db 0.0.5 → 0.0.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 667d1745cc359f830957af95e1528e639c7fea55
4
- data.tar.gz: c2f1d5197e58042fdbcc760c638440dceb0c5c2b
3
+ metadata.gz: 8e73a3ed8c1a47239b1e830675503fd7c9950166
4
+ data.tar.gz: f2b0b31ab87a254510d8b5105bbb12953f15d726
5
5
  SHA512:
6
- metadata.gz: 0af7222de66fc8405b753d6bbe7269915571e871f012521939fb7d544755dd41fe0012f9dc07552256e59777b99b99f1d21e057f175ff23fa5ed42d73d2d6409
7
- data.tar.gz: dd258c4a4234fef195cfa4f5250d096c7aa877e3902a75d540ba23f92b309ef0b7ef9d8f0ac8c4e2b7585dbdacaefcb6a5408433b30be12d0abefa0282ba03fb
6
+ metadata.gz: 06d936571f953b49b43d06ae81e3ffdbe004abc30edca2d8691445999d5d7278157074f28fff6dea7621dac06dae65e0d69a5508ff3180e9fe26a3f4752e7198
7
+ data.tar.gz: 493861ce02eac98fa121e227320f62014ec7b62ac34ac2e972a72b3eee5dcbbbe8244bdb72a0f5f13609607dbfeec7b79aa37d17549d754e016cf880279f9eb8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.0.6
2
+
3
+ * Fix incompatible read_attribute method alias
4
+
1
5
  ## v0.0.5
2
6
 
3
7
  * Models can now be reloaded.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- remote_db (0.0.4)
4
+ remote_db (0.0.5)
5
5
  activerecord (>= 3.0)
6
6
  activesupport (>= 3.0)
7
7
 
@@ -6,17 +6,25 @@ module RemoteDb
6
6
  class ForbiddenColumnException < Exception; end
7
7
 
8
8
  included do
9
- def _read_attribute_with_safety(name)
10
- original_db_column = self.class.original_columns.include?(name.to_sym)
11
- visible_db_column = self.class.visible_columns.include? (name.to_sym)
12
-
13
- if (original_db_column && visible_db_column) || !original_db_column
14
- _read_attribute_without_safety(name)
15
- else
16
- raise ForbiddenColumnException, "Column #{name} is not allowed for access."
9
+ # Rails 4.2 introduced a new attribute reader method `_read_attribute`.
10
+ # However, older versions of Rails (<= 4.1) use `read_attribute`.
11
+ [:_read_attribute, :read_attribute].each do |method|
12
+ if self.method_defined?(method)
13
+ define_method("#{method}_with_safety") do |name|
14
+ original_db_column = self.class.original_columns.include?(name.to_sym)
15
+ visible_db_column = self.class.visible_columns.include? (name.to_sym)
16
+
17
+ if (original_db_column && visible_db_column) || !original_db_column
18
+ _read_attribute_without_safety(name)
19
+ else
20
+ raise ForbiddenColumnException, "Column #{name} is not allowed for access."
21
+ end
22
+ end
23
+ alias_method_chain method, :safety
24
+
25
+ break
17
26
  end
18
27
  end
19
- alias_method_chain :_read_attribute, :safety
20
28
  end
21
29
 
22
30
  module ClassMethods
@@ -1,3 +1,3 @@
1
1
  module RemoteDb
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -110,11 +110,11 @@ describe RemoteDb do
110
110
  it 'should not allow accessing hidden columns' do
111
111
  person = TestDb::Person.first
112
112
  expect {
113
- puts person.last_name
113
+ person.last_name
114
114
  }.to raise_error(RemoteDb::Concerns::RestrictedColumns::ForbiddenColumnException)
115
115
 
116
116
  expect {
117
- puts person[:last_name]
117
+ person[:last_name]
118
118
  }.to raise_error(RemoteDb::Concerns::RestrictedColumns::ForbiddenColumnException)
119
119
  end
120
120
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Omar Skalli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-02 00:00:00.000000000 Z
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport