attribute_guard 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +1 -0
- data/VERSION +1 -1
- data/lib/attribute_guard.rb +14 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00ca78d9fb2f442ce8c5d58b0950e6ae2406e7317cc0060b572083d85705b247
|
4
|
+
data.tar.gz: 447523ace443fcdeeb1312ea118e2c39dc0e8195cecb5e647aed1f70f4cb0c41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4c1f7e90bb839de650cf4f272c6269106136bd03e91f86674bd73b9d00c3da76ec43741b8389c57d4fc9cef5d505e27ced1e548e823941b34e89048a583fee6
|
7
|
+
data.tar.gz: 11a93fe37a9db10b1de8e41e511f06d80abbc4cbe2670f193f6d7208cd9247218f6245c9d696aef716da9e55e5a26fd24e1a4a4112cb4f634620df66972d3413
|
data/CHANGELOG.md
CHANGED
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
-
## 1.0.
|
7
|
+
## 1.0.1
|
8
|
+
|
9
|
+
### Added
|
10
|
+
- Optimize object shapes for the Ruby interpreter by declaring instance variables in constructors.
|
11
|
+
|
12
|
+
## 1.0.0
|
8
13
|
|
9
14
|
### Added
|
10
15
|
- Initial release.
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Active Record Attribute Guard
|
2
2
|
|
3
3
|
[![Continuous Integration](https://github.com/bdurand/attribute_guard/actions/workflows/continuous_integration.yml/badge.svg)](https://github.com/bdurand/attribute_guard/actions/workflows/continuous_integration.yml)
|
4
|
+
[![Regression Test](https://github.com/bdurand/attribute_guard/actions/workflows/regression_test.yml/badge.svg)](https://github.com/bdurand/attribute_guard/actions/workflows/regression_test.yml)
|
4
5
|
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
|
5
6
|
|
6
7
|
This Ruby gem provides an extension for ActiveRecord allowing you to declare certain attributes in a model to be locked. Locked attributes cannot be changed once a record is created unless you explicitly allow changes.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/lib/attribute_guard.rb
CHANGED
@@ -42,6 +42,15 @@ module AttributeGuard
|
|
42
42
|
private_class_method :locked_attributes
|
43
43
|
|
44
44
|
validates_with LockedAttributesValidator
|
45
|
+
|
46
|
+
prepend Initializer
|
47
|
+
end
|
48
|
+
|
49
|
+
module Initializer
|
50
|
+
def initialize(*)
|
51
|
+
@unlocked_attributes = nil
|
52
|
+
super
|
53
|
+
end
|
45
54
|
end
|
46
55
|
|
47
56
|
# Validator that checks for changes to locked attributes.
|
@@ -110,6 +119,7 @@ module AttributeGuard
|
|
110
119
|
return if attributes.empty?
|
111
120
|
|
112
121
|
@unlocked_attributes ||= Set.new
|
122
|
+
|
113
123
|
if block_given?
|
114
124
|
save_val = @unlocked_attributes
|
115
125
|
begin
|
@@ -136,19 +146,15 @@ module AttributeGuard
|
|
136
146
|
attribute = attribute.to_s
|
137
147
|
return false unless self.class.send(:locked_attributes).include?(attribute)
|
138
148
|
|
139
|
-
if
|
140
|
-
|
141
|
-
|
142
|
-
true
|
143
|
-
end
|
149
|
+
return true if @unlocked_attributes.nil?
|
150
|
+
|
151
|
+
!@unlocked_attributes.include?(attribute.to_s)
|
144
152
|
end
|
145
153
|
|
146
154
|
# Clears any unlocked attributes.
|
147
155
|
#
|
148
156
|
# @return [void]
|
149
157
|
def clear_unlocked_attributes
|
150
|
-
|
151
|
-
remove_instance_variable(:@unlocked_attributes)
|
152
|
-
end
|
158
|
+
@unlocked_attributes = nil
|
153
159
|
end
|
154
160
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: attribute_guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|