phurni-is_less_paranoid 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/IS_PARANOID_CHANGELOG +31 -0
- data/IS_PARANOID_README.textile +103 -0
- data/MIT-LICENSE +19 -0
- data/README.textile +220 -0
- data/Rakefile +24 -0
- data/VERSION.yml +4 -0
- data/init.rb +1 -0
- data/lib/is_less_paranoid.rb +304 -0
- data/rails/init.rb +2 -0
- data/reactive/init.rb +3 -0
- data/spec/database.yml +3 -0
- data/spec/is_less_paranoid_spec.rb +164 -0
- data/spec/is_paranoid_spec.rb +277 -0
- data/spec/lp_models.rb +28 -0
- data/spec/models.rb +94 -0
- data/spec/schema.rb +87 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +14 -0
- metadata +76 -0
data/spec/lp_models.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
class Company < ActiveRecord::Base #:nodoc:
|
2
|
+
is_less_paranoid
|
3
|
+
has_many :contacts, :class_name => 'ContactAlive', :dependent => :destroy
|
4
|
+
end
|
5
|
+
|
6
|
+
class Contact < ActiveRecord::Base #:nodoc:
|
7
|
+
is_less_paranoid
|
8
|
+
|
9
|
+
def self.get_my_name
|
10
|
+
name
|
11
|
+
end
|
12
|
+
|
13
|
+
has_many :addresses, :dependent => :destroy
|
14
|
+
belongs_to :company
|
15
|
+
end
|
16
|
+
|
17
|
+
class VipContact < Contact
|
18
|
+
end
|
19
|
+
|
20
|
+
class Address < ActiveRecord::Base #:nodoc:
|
21
|
+
is_less_paranoid :clone => :with_destroyed, :suffix => 'WithInvalid'
|
22
|
+
belongs_to :contact
|
23
|
+
end
|
24
|
+
|
25
|
+
class Project < ActiveRecord::Base #:nodoc:
|
26
|
+
belongs_to :company
|
27
|
+
belongs_to :manager, :class_name => 'Contact'
|
28
|
+
end
|
data/spec/models.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
class Person < ActiveRecord::Base #:nodoc:
|
2
|
+
validates_uniqueness_of :name
|
3
|
+
has_many :androids, :foreign_key => :owner_id, :dependent => :destroy
|
4
|
+
end
|
5
|
+
|
6
|
+
class Android < ActiveRecord::Base #:nodoc:
|
7
|
+
validates_uniqueness_of :name
|
8
|
+
has_many :components, :dependent => :destroy
|
9
|
+
has_one :sticker
|
10
|
+
has_many :memories, :foreign_key => 'parent_id'
|
11
|
+
|
12
|
+
is_less_paranoid :clone => false
|
13
|
+
|
14
|
+
# this code is to ensure that our destroy and restore methods
|
15
|
+
# work without triggering before/after_update callbacks
|
16
|
+
before_update :raise_hell
|
17
|
+
def raise_hell
|
18
|
+
raise "hell"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Component < ActiveRecord::Base #:nodoc:
|
23
|
+
is_less_paranoid :clone => false
|
24
|
+
belongs_to :android, :dependent => :destroy
|
25
|
+
has_many :sub_components, :dependent => :destroy
|
26
|
+
NEW_NAME = 'Something Else!'
|
27
|
+
|
28
|
+
after_destroy :change_name
|
29
|
+
def change_name
|
30
|
+
self.update_attribute(:name, NEW_NAME)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class SubComponent < ActiveRecord::Base #:nodoc:
|
35
|
+
is_less_paranoid :clone => false
|
36
|
+
belongs_to :component, :dependent => :destroy
|
37
|
+
end
|
38
|
+
|
39
|
+
class Memory < ActiveRecord::Base #:nodoc:
|
40
|
+
is_less_paranoid :clone => false
|
41
|
+
belongs_to :android, :class_name => "Android", :foreign_key => "parent_id"
|
42
|
+
end
|
43
|
+
|
44
|
+
class Sticker < ActiveRecord::Base #:nodoc
|
45
|
+
MM_NAME = "You've got method_missing"
|
46
|
+
|
47
|
+
# this simply serves to ensure that we don't break method_missing
|
48
|
+
# if it is implemented on a class and called before is_paranoid
|
49
|
+
def method_missing name, *args, &block
|
50
|
+
self.name = MM_NAME
|
51
|
+
end
|
52
|
+
|
53
|
+
is_less_paranoid :clone => false
|
54
|
+
belongs_to :android
|
55
|
+
end
|
56
|
+
|
57
|
+
class AndroidWithScopedUniqueness < ActiveRecord::Base #:nodoc:
|
58
|
+
set_table_name :androids
|
59
|
+
validates_uniqueness_of :name, :scope => :deleted_at
|
60
|
+
is_less_paranoid :clone => false
|
61
|
+
end
|
62
|
+
|
63
|
+
class Ninja < ActiveRecord::Base #:nodoc:
|
64
|
+
validates_uniqueness_of :name, :scope => :visible
|
65
|
+
is_less_paranoid :field => [:visible, false, true], :clone => false
|
66
|
+
|
67
|
+
alias_method :vanish, :destroy
|
68
|
+
end
|
69
|
+
|
70
|
+
class Pirate < ActiveRecord::Base #:nodoc:
|
71
|
+
is_less_paranoid :field => [:alive, false, true], :clone => false
|
72
|
+
end
|
73
|
+
|
74
|
+
class DeadPirate < ActiveRecord::Base #:nodoc:
|
75
|
+
set_table_name :pirates
|
76
|
+
is_less_paranoid :field => [:alive, true, false], :clone => false
|
77
|
+
end
|
78
|
+
|
79
|
+
class RandomPirate < ActiveRecord::Base #:nodoc:
|
80
|
+
set_table_name :pirates
|
81
|
+
|
82
|
+
def after_destroy
|
83
|
+
raise 'after_destroy works'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class UndestroyablePirate < ActiveRecord::Base #:nodoc:
|
88
|
+
set_table_name :pirates
|
89
|
+
is_less_paranoid :field => [:alive, false, true], :clone => false
|
90
|
+
|
91
|
+
def before_destroy
|
92
|
+
false
|
93
|
+
end
|
94
|
+
end
|
data/spec/schema.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
ActiveRecord::Schema.define(:version => 20090317164830) do
|
2
|
+
create_table "androids", :force => true do |t|
|
3
|
+
t.string "name"
|
4
|
+
t.integer "owner_id"
|
5
|
+
t.datetime "deleted_at"
|
6
|
+
t.datetime "created_at"
|
7
|
+
t.datetime "updated_at"
|
8
|
+
end
|
9
|
+
|
10
|
+
create_table "people", :force => true do |t|
|
11
|
+
t.string "name"
|
12
|
+
t.datetime "created_at"
|
13
|
+
t.datetime "updated_at"
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table "components", :force => true do |t|
|
17
|
+
t.string "name"
|
18
|
+
t.integer "android_id"
|
19
|
+
t.datetime "deleted_at"
|
20
|
+
t.datetime "created_at"
|
21
|
+
t.datetime "updated_at"
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table "sub_components", :force => true do |t|
|
25
|
+
t.string "name"
|
26
|
+
t.integer "component_id"
|
27
|
+
t.datetime "deleted_at"
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table "memories", :force => true do |t|
|
31
|
+
t.string "name"
|
32
|
+
t.integer "parent_id"
|
33
|
+
t.datetime "deleted_at"
|
34
|
+
end
|
35
|
+
|
36
|
+
create_table "stickers", :force => true do |t|
|
37
|
+
t.string "name"
|
38
|
+
t.integer "android_id"
|
39
|
+
t.datetime "deleted_at"
|
40
|
+
end
|
41
|
+
|
42
|
+
create_table "ninjas", :force => true do |t|
|
43
|
+
t.string "name"
|
44
|
+
t.boolean "visible", :default => false
|
45
|
+
end
|
46
|
+
|
47
|
+
create_table "pirates", :force => true do |t|
|
48
|
+
t.string "name"
|
49
|
+
t.boolean "alive", :default => true
|
50
|
+
end
|
51
|
+
|
52
|
+
create_table "companies", :force => true do |t|
|
53
|
+
t.string "name"
|
54
|
+
t.datetime "deleted_at"
|
55
|
+
t.datetime "created_at"
|
56
|
+
t.datetime "updated_at"
|
57
|
+
end
|
58
|
+
|
59
|
+
create_table "contacts", :force => true do |t|
|
60
|
+
t.string "firstname"
|
61
|
+
t.string "lastname"
|
62
|
+
t.integer "company_id"
|
63
|
+
t.string "type"
|
64
|
+
t.datetime "deleted_at"
|
65
|
+
t.datetime "created_at"
|
66
|
+
t.datetime "updated_at"
|
67
|
+
end
|
68
|
+
|
69
|
+
create_table "addresses", :force => true do |t|
|
70
|
+
t.string "street"
|
71
|
+
t.string "city"
|
72
|
+
t.integer "zipcode"
|
73
|
+
t.integer "contact_id"
|
74
|
+
t.datetime "deleted_at"
|
75
|
+
t.datetime "created_at"
|
76
|
+
t.datetime "updated_at"
|
77
|
+
end
|
78
|
+
|
79
|
+
create_table "projects", :force => true do |t|
|
80
|
+
t.string "name"
|
81
|
+
t.integer "company_id"
|
82
|
+
t.integer "manager_id"
|
83
|
+
t.datetime "deleted_at"
|
84
|
+
t.datetime "created_at"
|
85
|
+
t.datetime "updated_at"
|
86
|
+
end
|
87
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require "#{File.dirname(__FILE__)}/../lib/is_less_paranoid"
|
3
|
+
require 'activerecord'
|
4
|
+
require 'yaml'
|
5
|
+
require 'spec'
|
6
|
+
|
7
|
+
def connect(environment)
|
8
|
+
conf = YAML::load(File.open(File.dirname(__FILE__) + '/database.yml'))
|
9
|
+
ActiveRecord::Base.establish_connection(conf[environment])
|
10
|
+
end
|
11
|
+
|
12
|
+
# Open ActiveRecord connection
|
13
|
+
connect('test')
|
14
|
+
load(File.dirname(__FILE__) + "/schema.rb")
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: phurni-is_less_paranoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pascal Hurni
|
8
|
+
- Jeffrey Chupp
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-07-07 00:00:00 -07:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: ""
|
18
|
+
email: pascal_hurni@fastmail.fm
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.textile
|
25
|
+
files:
|
26
|
+
- README.textile
|
27
|
+
- IS_PARANOID_README.textile
|
28
|
+
- IS_PARANOID_CHANGELOG
|
29
|
+
- MIT-LICENSE
|
30
|
+
- Rakefile
|
31
|
+
- VERSION.yml
|
32
|
+
- init.rb
|
33
|
+
- lib/is_less_paranoid.rb
|
34
|
+
- rails/init.rb
|
35
|
+
- reactive/init.rb
|
36
|
+
- spec/database.yml
|
37
|
+
- spec/is_paranoid_spec.rb
|
38
|
+
- spec/is_less_paranoid_spec.rb
|
39
|
+
- spec/models.rb
|
40
|
+
- spec/lp_models.rb
|
41
|
+
- spec/schema.rb
|
42
|
+
- spec/spec.opts
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/phurni/is_less_paranoid/
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.2.0
|
67
|
+
signing_key:
|
68
|
+
specification_version: 2
|
69
|
+
summary: ActiveRecord 2.3 compatible gem "allowing you to hide and restore records without actually deleting them." Yes, like acts_as_paranoid, only with less code and less complexity. Extended version to allow associated records to still be alive.
|
70
|
+
test_files:
|
71
|
+
- spec/is_paranoid_spec.rb
|
72
|
+
- spec/is_less_paranoid_spec.rb
|
73
|
+
- spec/models.rb
|
74
|
+
- spec/lp_models.rb
|
75
|
+
- spec/schema.rb
|
76
|
+
- spec/spec_helper.rb
|