activerecord-immutable 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97476c3b5c4d60b9230bfe4ede812bebd84a2214
4
+ data.tar.gz: 61f7fe7af3c246fdc529bf45a703686ff4c79bb7
5
+ SHA512:
6
+ metadata.gz: 45fd96c5e91ef9c9e33fb12c1b947874da28eb394446b4ab0aab2ccfccb1f5e9edc3181608f65720c45dd585aa1764b4e8fadedcef1b7bc1ca88fbaa28942181
7
+ data.tar.gz: aaef4a88606b87cf008b327fbc3b798df42d875db21362e5ac4550ba33fc57d980ccd82b2e4541dce02a8f3397c47f696de39c8a80330dab01ada9f54b18205e
@@ -0,0 +1,2 @@
1
+ bin
2
+ Gemfile.lock
@@ -0,0 +1,12 @@
1
+ sudo: false
2
+
3
+ cache: bundler
4
+
5
+ rvm:
6
+ - 1.9
7
+ - 2.1
8
+
9
+ gemfile:
10
+ - ci/ar32.gemfile
11
+ - ci/ar41.gemfile
12
+ - ci/ar42.gemfile
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord-immutable.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Matt Rohrer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Activerecord::Immutable
2
+
3
+ A tiny mixin to make your ActiveRecord models immutable after creation.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'activerecord-immutable'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install activerecord-immutable
20
+
21
+ ## Usage
22
+
23
+ Include the `ActiveRecord::Immutable` module in your `ActiveRecord::Base`
24
+ class:
25
+
26
+ ```ruby
27
+ class DomainEvent < ActiveRecord::Base
28
+ include ActiveRecord::Immutable
29
+ end
30
+ ```
31
+
32
+ You'll be allowed to create instances, but any attempt to update, touch, delete,
33
+ destroy, etc. will raise an `ActiveRecord::ReadOnlyRecord` exception.
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/activerecord-immutable/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task default: [:test]
@@ -0,0 +1,27 @@
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 = "activerecord-immutable"
8
+ spec.version = ActiveRecord::Immutable::VERSION
9
+ spec.authors = ["Matt Rohrer"]
10
+ spec.email = ["matt@prognostikos.com"]
11
+ spec.summary = %q{A tiny mixin to make your ActiveRecord models immutable.}
12
+ spec.description = %q{Include ActiveRecord::Immutable in your ActiveRecord models to make your tables append-only.}
13
+ spec.homepage = "https://github.com/prognostikos/activerecord-immutable"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_runtime_dependency "activerecord", ">= 3.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "railties"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "sqlite3"
27
+ end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.2.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 4.1.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 4.2.0'
4
+
5
+ gemspec path: '../'
@@ -0,0 +1,27 @@
1
+ require "active_record/immutable/version"
2
+
3
+ module ActiveRecord
4
+ module Immutable
5
+ def self.included(model)
6
+ model.before_destroy :raise_error
7
+ end
8
+
9
+ def readonly?
10
+ persisted?
11
+ end
12
+
13
+ def touch
14
+ raise_error
15
+ end
16
+
17
+ def delete
18
+ raise_error
19
+ end
20
+
21
+ private
22
+
23
+ def raise_error
24
+ raise ActiveRecord::ReadOnlyRecord
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveRecord
2
+ module Immutable
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'test_helper'
2
+
3
+ class ActiveRecord::ImmutableTest < MiniTest::Unit::TestCase
4
+ def test_models_can_be_persisted
5
+ assert DomainEvent.create
6
+ end
7
+
8
+ def test_saving_a_persisted_model_raises_error
9
+ event = DomainEvent.create
10
+
11
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
12
+ event.save
13
+ end
14
+
15
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
16
+ event.save!
17
+ end
18
+ end
19
+
20
+ def test_updating_a_persisted_model_raises_error
21
+ event = DomainEvent.create
22
+
23
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
24
+ event.update_attribute(:created_at, Time.now)
25
+ end
26
+
27
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
28
+ event.update_attributes(created_at: Time.now, updated_at: Time.now)
29
+ end
30
+ end
31
+
32
+ def test_touching_a_persisted_model_raises_error
33
+ event = DomainEvent.create
34
+
35
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
36
+ event.touch
37
+ end
38
+ end
39
+
40
+ def test_destroying_a_persisted_model_raises_error
41
+ event = DomainEvent.create
42
+
43
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
44
+ event.destroy
45
+ end
46
+
47
+ if event.respond_to?(:destroy!)
48
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
49
+ event.destroy!
50
+ end
51
+ end
52
+ end
53
+
54
+ def test_delete_raises_error
55
+ event = DomainEvent.create
56
+
57
+ assert_raises(ActiveRecord::ReadOnlyRecord) do
58
+ event.delete
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,23 @@
1
+ require 'rails'
2
+ require 'rails/test_help'
3
+ require 'active_record'
4
+
5
+ $: << 'lib'
6
+
7
+ require 'active_record/immutable'
8
+
9
+ ActiveRecord::Base.establish_connection(
10
+ adapter: "sqlite3",
11
+ database: ":memory:")
12
+
13
+ silence_stream(STDOUT) do
14
+ ActiveRecord::Schema.define do
15
+ create_table "domain_events", force: true do |t|
16
+ t.timestamps
17
+ end
18
+ end
19
+ end
20
+
21
+ class DomainEvent < ActiveRecord::Base
22
+ include ActiveRecord::Immutable
23
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-immutable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Matt Rohrer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Include ActiveRecord::Immutable in your ActiveRecord models to make your
84
+ tables append-only.
85
+ email:
86
+ - matt@prognostikos.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - activerecord-immutable.gemspec
98
+ - ci/ar32.gemfile
99
+ - ci/ar41.gemfile
100
+ - ci/ar42.gemfile
101
+ - lib/active_record/immutable.rb
102
+ - lib/active_record/immutable/version.rb
103
+ - test/lib/active_record/immutable_test.rb
104
+ - test/test_helper.rb
105
+ homepage: https://github.com/prognostikos/activerecord-immutable
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A tiny mixin to make your ActiveRecord models immutable.
129
+ test_files:
130
+ - test/lib/active_record/immutable_test.rb
131
+ - test/test_helper.rb