active_record_immutable 0.0.1

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Benjamin Feng
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ ActiveRecordImmutable
2
+ ------
3
+
4
+ Make ActiveRecord objects immutable.
5
+
6
+ Installation
7
+ ======
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```console
12
+ gem 'active_record_immutable'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```console
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```console
24
+ $ gem install active_record_immutable
25
+ ```
26
+
27
+ Usage
28
+ =====
29
+
30
+ ```ruby
31
+ class Record << ActiveRecord::Base
32
+ include ActiveRecordImmutable
33
+ end
34
+ ```
35
+
36
+ Contributing
37
+ =====
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_record_immutable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_record_immutable"
8
+ spec.version = ActiveRecordImmutable::VERSION
9
+ spec.authors = ["Benjamin Feng"]
10
+ spec.email = ["contact@fengb.info"]
11
+ spec.description = %q{Make ActiveRecord objects immutable.}
12
+ spec.summary = %q{Make ActiveRecord objects immutable.}
13
+ spec.homepage = "https://github.com/fengb/active_record_immutable"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "activerecord", ">= 3.1"
24
+ spec.add_development_dependency "temping", "~> 3.2.0"
25
+ spec.add_development_dependency "rspec", "~> 2.0"
26
+ end
@@ -0,0 +1,13 @@
1
+ require "active_record_immutable/version"
2
+
3
+ module ActiveRecordImmutable
4
+ def self.extended(base)
5
+ base.after_save do |record|
6
+ record.readonly!
7
+ end
8
+
9
+ base.after_find do |record|
10
+ record.readonly!
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveRecordImmutable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ require 'active_record_immutable'
3
+
4
+
5
+ describe ActiveRecordImmutable do
6
+ Temping.create :klass do
7
+ with_columns do |t|
8
+ t.string :attr
9
+ end
10
+
11
+ extend ActiveRecordImmutable
12
+ end
13
+
14
+ let(:instance) { Klass.create }
15
+
16
+ describe 'from saved' do
17
+ it 'is unsavable after save' do
18
+ expect{instance.save}.to raise_error(ActiveRecord::ReadOnlyRecord)
19
+ end
20
+
21
+ it 'is undestroyable after save' do
22
+ expect{instance.destroy}.to raise_error(ActiveRecord::ReadOnlyRecord)
23
+ end
24
+ end
25
+
26
+ describe 'from find' do
27
+ let(:from_db) { Klass.first }
28
+
29
+ it 'is unsavable from record find' do
30
+ expect{from_db.save}.to raise_error(ActiveRecord::ReadOnlyRecord)
31
+ end
32
+
33
+ it 'is undestroyable from record find' do
34
+ expect{from_db.destroy}.to raise_error(ActiveRecord::ReadOnlyRecord)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ require 'temping'
2
+ require 'active_record'
3
+
4
+
5
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record_immutable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Benjamin Feng
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activerecord
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ - !ruby/object:Gem::Dependency
63
+ name: temping
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 3.2.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 3.2.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '2.0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '2.0'
94
+ description: Make ActiveRecord objects immutable.
95
+ email:
96
+ - contact@fengb.info
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - active_record_immutable.gemspec
107
+ - lib/active_record_immutable.rb
108
+ - lib/active_record_immutable/version.rb
109
+ - spec/active_record_immutable_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/fengb/active_record_immutable
112
+ licenses:
113
+ - MIT
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 1.8.23
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Make ActiveRecord objects immutable.
136
+ test_files:
137
+ - spec/active_record_immutable_spec.rb
138
+ - spec/spec_helper.rb
139
+ has_rdoc: