locked_attributes 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,32 @@
1
- = LockedAttributes
1
+ # LockedAttributes
2
2
 
3
3
  Simple module that makes ActiveRecord attributes locked when the model has been saved.
4
4
  Should one attempt to change a locked attribute, the model will invalidate with a `:locked` message.
5
5
 
6
- == Contributing to locked_attributes
6
+ ## Usage
7
+
8
+ ```ruby
9
+ class Post < ActiveRecord::Base
10
+ include LockedAttributes
11
+ lock_attributes :author
12
+ end
13
+ ```
14
+
15
+ ```ruby
16
+ post = Post.new
17
+ post.author = Author.find(1)
18
+ post.save
19
+
20
+ post.author = Author.find(2)
21
+ post.valid? # => false
22
+ ```
23
+
24
+ ## Todo
25
+
26
+ * Allow for several strategies (exception)
27
+ * Make it possible to lock attributes to their first value (not depending on #new_record?)
28
+
29
+ ## Contributing to locked_attributes
7
30
 
8
31
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
9
32
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
@@ -13,7 +36,7 @@ Should one attempt to change a locked attribute, the model will invalidate with
13
36
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
14
37
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
15
38
 
16
- == Copyright
39
+ ## Copyright
17
40
 
18
41
  Copyright (c) 2013 Theodor Tonum. See LICENSE.txt for
19
42
  further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -12,21 +12,19 @@ module LockedAttributes
12
12
  end
13
13
  end
14
14
 
15
- module InstanceMethods
16
- def locked_attributes
17
- self.class.locked_attributes || []
18
- end
15
+ def locked_attributes
16
+ self.class.locked_attributes || []
17
+ end
19
18
 
20
- def validate_locked_attributes
21
- for attribute in locked_and_changed_attributes
22
- errors.add(attribute, :locked)
23
- end
19
+ def validate_locked_attributes
20
+ for attribute in locked_and_changed_attributes
21
+ errors.add(attribute, :locked)
24
22
  end
23
+ end
25
24
 
26
- private
25
+ private
27
26
 
28
- def locked_and_changed_attributes
29
- changed & locked_attributes
30
- end
27
+ def locked_and_changed_attributes
28
+ changed & locked_attributes
31
29
  end
32
30
  end
@@ -5,16 +5,16 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "locked_attributes"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Theodor Tonum"]
12
- s.date = "2013-02-22"
12
+ s.date = "2013-02-25"
13
13
  s.description = "Make persisted models have locked attributes."
14
14
  s.email = "theodor@tonum.no"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
- "README.rdoc"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
  "Gemfile",
23
23
  "Gemfile.lock",
24
24
  "LICENSE.txt",
25
- "README.rdoc",
25
+ "README.md",
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "lib/locked_attributes.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locked_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-22 00:00:00.000000000 Z
12
+ date: 2013-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -129,14 +129,14 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files:
131
131
  - LICENSE.txt
132
- - README.rdoc
132
+ - README.md
133
133
  files:
134
134
  - .document
135
135
  - .rspec
136
136
  - Gemfile
137
137
  - Gemfile.lock
138
138
  - LICENSE.txt
139
- - README.rdoc
139
+ - README.md
140
140
  - Rakefile
141
141
  - VERSION
142
142
  - lib/locked_attributes.rb
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  segments:
160
160
  - 0
161
- hash: 127442411858154258
161
+ hash: 3186434932677846296
162
162
  required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  none: false
164
164
  requirements: