pgcrypto 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ 0.2.1
2
+ * Added ActiveModel::Dirty support, so you can now call *_changed?
3
+ on your models tracking pgcrypto columns.
4
+
1
5
  0.2.0
2
6
  * Overhauled key system. Unfortunately, for performance reasons
3
7
  and due to the insanely hacked nature of PGCrypto, multiple keys
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/pgcrypto.rb CHANGED
@@ -28,6 +28,9 @@ module PGCrypto
28
28
  # Stash the encryption type in our module so various monkeypatches can access it later!
29
29
  PGCrypto[table_name][column_name] = options.symbolize_keys
30
30
 
31
+ # Add dynamic attribute readers/writers for ActiveModel APIs
32
+ # define_attribute_method column_name
33
+
31
34
  # Add attribute readers/writers to keep this baby as fluid and clean as possible.
32
35
  start_line = __LINE__; pgcrypto_methods = <<-PGCRYPTO_METHODS
33
36
  def #{column_name}
@@ -38,6 +41,7 @@ module PGCrypto
38
41
 
39
42
  # We write the attribute directly to its child value. Neato!
40
43
  def #{column_name}=(value)
44
+ attribute_will_change!(:#{column_name}) if value != @_pgcrypto_#{column_name}.try(:value)
41
45
  if value.nil?
42
46
  pgcrypto_columns.select{|column| column.name == "#{column_name}"}.each(&:mark_for_destruction)
43
47
  remove_instance_variable("@_pgcrypto_#{column_name}") if defined?(@_pgcrypto_#{column_name})
@@ -46,6 +50,10 @@ module PGCrypto
46
50
  @_pgcrypto_#{column_name}.value = value
47
51
  end
48
52
  end
53
+
54
+ def #{column_name}_changed?
55
+ changed.include?(:#{column_name})
56
+ end
49
57
  PGCRYPTO_METHODS
50
58
 
51
59
  class_eval pgcrypto_methods, __FILE__, start_line
@@ -46,5 +46,18 @@ describe PGCrypto do
46
46
  model = PGCryptoTestModel.create!(:test_column => 'i am findable!')
47
47
  PGCryptoTestModel.where(:test_column => model.test_column).count.should == 1
48
48
  end
49
+
50
+ it "should track changes" do
51
+ model = PGCryptoTestModel.create!(:test_column => 'i am clean')
52
+ model.test_column = "now i'm not!"
53
+ model.test_column_changed?.should be_true
54
+ end
55
+
56
+
57
+ it "should not be dirty if unchanged" do
58
+ model = PGCryptoTestModel.create!(:test_column => 'i am clean')
59
+ model.test_column = 'i am clean'
60
+ model.test_column_changed?.should_not be_true
61
+ end
49
62
  end
50
63
  end
data/spec/spec_helper.rb CHANGED
@@ -30,7 +30,6 @@ RSpec.configure do |config|
30
30
  # Now connect to the newly created database
31
31
  ActiveRecord::Base.establish_connection(database_config)
32
32
 
33
-
34
33
  silence_stream(STDOUT) do
35
34
  # ...and load in the pgcrypto extension
36
35
  ActiveRecord::Base.connection.execute(%[CREATE EXTENSION pgcrypto])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgcrypto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2012-06-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70147572219000 !ruby/object:Gem::Requirement
16
+ requirement: &70340389612080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70147572219000
24
+ version_requirements: *70340389612080
25
25
  description: ! "\n PGCrypto is an ActiveRecord::Base extension that allows you
26
26
  to asymmetrically\n encrypt PostgreSQL columns with as little trouble as possible.
27
27
  It's totally\n freaking rad.\n "
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 1.8.10
79
+ rubygems_version: 1.8.15
80
80
  signing_key:
81
81
  specification_version: 3
82
82
  summary: A transparent ActiveRecord::Base extension for encrypted columns