attribute_access_controllable 1.1.2 → 1.1.3
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.
- data/.yardopts +1 -0
- data/lib/attribute_access_controllable.rb +13 -6
- data/lib/attribute_access_controllable/version.rb +1 -1
- metadata +3 -1
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--main README.md lib/attribute_access_controllable.rb - LICENSE README.md
|
@@ -8,21 +8,20 @@ module AttributeAccessControllable
|
|
8
8
|
validate :read_only_attributes_unchanged, :on => :update, :unless => :skip_read_only
|
9
9
|
end
|
10
10
|
|
11
|
+
# Mark an attribute as read-only
|
12
|
+
# @param [Symbol] attributes on the model
|
13
|
+
# @return [void]
|
11
14
|
def attr_read_only(*attributes)
|
12
15
|
self.read_only_attributes = Set.new(attributes.map { |a| a.to_s }) + (read_only_attributes || [])
|
13
16
|
end
|
14
17
|
|
18
|
+
# @param [Symbol] attribute on the model
|
19
|
+
# @return [Boolean] attribute is read-only
|
15
20
|
def read_only_attribute?(attribute)
|
16
21
|
return false if read_only_attributes.nil?
|
17
22
|
read_only_attributes.member?(attribute.to_s)
|
18
23
|
end
|
19
24
|
|
20
|
-
def read_only_attributes_unchanged
|
21
|
-
changed_attributes.each_key do |attr|
|
22
|
-
errors.add(attr) << "is read_only" if read_only_attribute?(attr)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
25
|
def save(options = {})
|
27
26
|
self.skip_read_only = options.delete(:skip_read_only)
|
28
27
|
super
|
@@ -32,4 +31,12 @@ module AttributeAccessControllable
|
|
32
31
|
self.skip_read_only = options.delete(:skip_read_only)
|
33
32
|
super
|
34
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def read_only_attributes_unchanged
|
38
|
+
changed_attributes.each_key do |attr|
|
39
|
+
errors.add(attr) << "is read_only" if read_only_attribute?(attr)
|
40
|
+
end
|
41
|
+
end
|
35
42
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute_access_controllable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- .gitignore
|
169
169
|
- .pairs
|
170
170
|
- .rspec
|
171
|
+
- .yardopts
|
171
172
|
- Gemfile
|
172
173
|
- LICENSE
|
173
174
|
- README.md
|
@@ -224,3 +225,4 @@ test_files:
|
|
224
225
|
- spec/attribute_access_controllable_spec.rb
|
225
226
|
- spec/generators/attribute_access_generator_spec.rb
|
226
227
|
- spec/spec_helper.rb
|
228
|
+
has_rdoc:
|