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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a485b9e0bc322539e0ac6b7014eb40824c4d94227fc216fab8add8a4f7a201fe
4
- data.tar.gz: 792be937f2a9c6a611773d99c7e9f42c84546e3d1693046a4b7d3ab7b06d7097
3
+ metadata.gz: 00ca78d9fb2f442ce8c5d58b0950e6ae2406e7317cc0060b572083d85705b247
4
+ data.tar.gz: 447523ace443fcdeeb1312ea118e2c39dc0e8195cecb5e647aed1f70f4cb0c41
5
5
  SHA512:
6
- metadata.gz: 36e1b736350dba0238b811205629d6dd4e3b15ef12a60084cb56f78104d90e0cf1b2df797ef555e352e023678d7f838302a583769e876f967a4e9fa5d5306452
7
- data.tar.gz: d961953fc003bfcbada924c84a07b24aaacbca72d1d14c06d1d148ef76d5fb0926a4ecac6999758a63761c85873bdabcf5d76c1eebfda1285cd299ef3ecf6a69
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.0 (unreleased)
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.0
1
+ 1.0.1
@@ -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 defined?(@unlocked_attributes)
140
- !@unlocked_attributes.include?(attribute.to_s)
141
- else
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
- if defined?(@unlocked_attributes)
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.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-07-28 00:00:00.000000000 Z
11
+ date: 2023-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord