kakurenbo 0.1.2 → 0.1.3

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: 1db2fcbe670f950ac46f450c5365921042ec298b
4
- data.tar.gz: b52de24c10f252966d25f629b86679142fcb0024
3
+ metadata.gz: 9d17f226c87b76328e3f11a74e9224af2c25ec7d
4
+ data.tar.gz: 85ecc8c56e701cf1500416a969733c6bb098c1e6
5
5
  SHA512:
6
- metadata.gz: ad49f6368d5bd864abbe3847ceeae2db12f0df1a55977fc3de36b94758ea6ce561be9e60504e4218f40afaba2c29b174cc1122fc71bc8c7f936fa716e664fbec
7
- data.tar.gz: 7f198fd7fb0ab7a0cd41e17ffcffe8f2c3e8464759d0db95cc7334c79202765f57195afdbd628bb8a1a3311f8021e3122d69e0b89b895db26121b97498933575
6
+ metadata.gz: 28c44c302564b18f8930dac1a90553e83c8bbbf0a3186575eafce1898a75e8902a88c3f0d1a06f02d0064ab3a61e37e1ef6d7bbd1a9ee9bf32a57d3ba7c2f4fa
7
+ data.tar.gz: 44d3f77630f0872526c21d94761f81e98dbe5e52f43de9e3e7e97fec8ed09f1bc5d8a9b5bfc95096ceebc8b901ef36227316dbfc008d0497db8eb07db48b99f0
@@ -8,3 +8,4 @@ rvm:
8
8
  env:
9
9
  - RAILS=3.2.16
10
10
  - RAILS=4.0.2
11
+ - RAILS=4.1.0
@@ -8,14 +8,9 @@ module Kakurenbo
8
8
  module ClassMethods
9
9
  # Initialize Kakurenbo in child class.
10
10
  def inherited(child_class)
11
- child_class.instance_eval {
12
- begin
13
- next unless column_names.include?('deleted_at')
14
- remodel_as_soft_delete
15
- rescue
16
- # When exec first db:migrate and db:migrate:reset.
17
- end
18
- }
11
+ child_class.instance_eval do
12
+ remodel_as_soft_delete if has_kakurenbo_column?
13
+ end
19
14
  super
20
15
  end
21
16
 
@@ -35,10 +30,10 @@ module Kakurenbo
35
30
  alias_method :hard_destroy!, :destroy
36
31
 
37
32
  class_attribute :kakurenbo_column
38
- self.kakurenbo_column = options[:column]
39
-
40
33
  include Kakurenbo::SoftDeleteCore
41
34
  end
35
+
36
+ self.kakurenbo_column = options[:column]
42
37
  end
43
38
  alias_method :acts_as_paranoid, :remodel_as_soft_delete
44
39
 
@@ -46,6 +41,24 @@ module Kakurenbo
46
41
  def paranoid?
47
42
  false
48
43
  end
44
+
45
+ # When set table name, remodel.
46
+ def table_name=(value)
47
+ super
48
+ remodel_as_soft_delete if has_kakurenbo_column?
49
+ end
50
+
51
+ private
52
+ # Check if Model has kakurenbo_column.
53
+ #
54
+ # @return [Boolean] result.
55
+ def has_kakurenbo_column?
56
+ begin
57
+ column_names.include?('deleted_at')
58
+ rescue
59
+ false
60
+ end
61
+ end
49
62
  end
50
63
 
51
64
  def paranoid?
@@ -1,3 +1,3 @@
1
1
  module Kakurenbo
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -4,6 +4,7 @@ describe Kakurenbo::MixinARBase do
4
4
  create_temp_table(:hard_deletes) {}
5
5
  create_temp_table(:soft_deletes) {|t| t.datetime :deleted_at}
6
6
  create_temp_table(:other_columns){|t| t.datetime :destroyed_at}
7
+ create_temp_table(:other_table_name) {|t| t.datetime :deleted_at}
7
8
 
8
9
  context 'when mixin ActiveRecord::Base' do
9
10
  it 'has paranoid? in class methods.'do
@@ -54,4 +55,20 @@ describe Kakurenbo::MixinARBase do
54
55
  expect(OtherColumn.kakurenbo_column).to eq(:destroyed_at)
55
56
  end
56
57
  end
58
+
59
+ context 'when define class of DiffTableName' do
60
+ before :all do
61
+ class DiffTableName < ActiveRecord::Base
62
+ self.table_name='other_table_name'
63
+ end
64
+ end
65
+
66
+ it 'table_name is right.' do
67
+ expect(DiffTableName.table_name).to eq('other_table_name')
68
+ end
69
+
70
+ it 'paranoid? return true.' do
71
+ expect(DiffTableName.paranoid?).to be_true
72
+ end
73
+ end
57
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kakurenbo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - alfa-jpn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-04 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler