deprecated_attributes 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 74803eb7dabb961cb77ba83ca706c3abe6b113242ffd695a4919921c9653730d
4
+ data.tar.gz: 10442fe32304ae4d36611e33893aef7ad6e7fddc39ea9f2a4a79fefd5e1e368b
5
+ SHA512:
6
+ metadata.gz: 31b1132943262fde29bc9d42cfb3071ba017be6e177f7ef0999983e6f0158498d65e653e5b68d960dac44c8c9ddb2be257d559b0a0d54072015a39dd5a4159d6
7
+ data.tar.gz: 84a38f00538761a42811abdd669ac67600fa52f232128c509dec29a372ad5cfc370e8340a089ebe980df9fa659c758efb2887064bec6ef50dc35dd1d388f7dc8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,7 @@
1
+ require: standard
2
+
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 3.0
6
+ inherit_gem:
7
+ standard: config/base.yml
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/testdouble/standard
3
+ ruby_version: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-02-23
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nora.alvarado@hey.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in deprecated_attributes.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deprecated_attributes (0.1.0)
5
+ activesupport (~> 7.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (7.0.4.2)
11
+ activesupport (= 7.0.4.2)
12
+ activerecord (7.0.4.2)
13
+ activemodel (= 7.0.4.2)
14
+ activesupport (= 7.0.4.2)
15
+ activesupport (7.0.4.2)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ ast (2.4.2)
21
+ coderay (1.1.3)
22
+ concurrent-ruby (1.2.0)
23
+ diff-lcs (1.5.0)
24
+ i18n (1.12.0)
25
+ concurrent-ruby (~> 1.0)
26
+ json (2.6.3)
27
+ language_server-protocol (3.17.0.3)
28
+ method_source (1.0.0)
29
+ minitest (5.17.0)
30
+ parallel (1.22.1)
31
+ parser (3.2.1.0)
32
+ ast (~> 2.4.1)
33
+ pry (0.14.2)
34
+ coderay (~> 1.1)
35
+ method_source (~> 1.0)
36
+ rainbow (3.1.1)
37
+ rake (13.0.6)
38
+ regexp_parser (2.7.0)
39
+ rexml (3.2.5)
40
+ rspec (3.12.0)
41
+ rspec-core (~> 3.12.0)
42
+ rspec-expectations (~> 3.12.0)
43
+ rspec-mocks (~> 3.12.0)
44
+ rspec-core (3.12.1)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-expectations (3.12.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.12.0)
49
+ rspec-mocks (3.12.3)
50
+ diff-lcs (>= 1.2.0, < 2.0)
51
+ rspec-support (~> 3.12.0)
52
+ rspec-support (3.12.0)
53
+ rubocop (1.44.1)
54
+ json (~> 2.3)
55
+ parallel (~> 1.10)
56
+ parser (>= 3.2.0.0)
57
+ rainbow (>= 2.2.2, < 4.0)
58
+ regexp_parser (>= 1.8, < 3.0)
59
+ rexml (>= 3.2.5, < 4.0)
60
+ rubocop-ast (>= 1.24.1, < 2.0)
61
+ ruby-progressbar (~> 1.7)
62
+ unicode-display_width (>= 2.4.0, < 3.0)
63
+ rubocop-ast (1.26.0)
64
+ parser (>= 3.2.1.0)
65
+ rubocop-performance (1.15.2)
66
+ rubocop (>= 1.7.0, < 2.0)
67
+ rubocop-ast (>= 0.4.0)
68
+ ruby-progressbar (1.11.0)
69
+ sqlite3 (1.6.0-arm64-darwin)
70
+ standard (1.24.3)
71
+ language_server-protocol (~> 3.17.0.2)
72
+ rubocop (= 1.44.1)
73
+ rubocop-performance (= 1.15.2)
74
+ tzinfo (2.0.6)
75
+ concurrent-ruby (~> 1.0)
76
+ unicode-display_width (2.4.2)
77
+
78
+ PLATFORMS
79
+ arm64-darwin-22
80
+
81
+ DEPENDENCIES
82
+ activerecord (~> 7.0.0)
83
+ deprecated_attributes!
84
+ pry (~> 0.14.2)
85
+ rake (~> 13.0)
86
+ rspec (~> 3.0)
87
+ sqlite3 (~> 1.6.0)
88
+ standard (~> 1.3)
89
+
90
+ BUNDLED WITH
91
+ 2.4.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Nora Alvarado
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # DeprecatedAttributes (WIP)
2
+
3
+ **This is a work in progress and learning exercise** DeprecatedAttributes provides a straightforward and unobtrusive method for flagging deprecated attributes in your model. When these attributes are accessed, a deprecation warning message will be logged. Additionally, an exception can be raised if desired along with a trace of where the deprecated attribute was called.
4
+
5
+ ## Installation
6
+
7
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
16
+
17
+ ## Configuration
18
+
19
+ You can use the configure method and pass a block that takes a config parameter. Within this block, you can set various options for DeprecatedAttributes.
20
+
21
+ `enable:` Set this option to true to enable some feature.
22
+
23
+ `full_trace:` Set this option to false to disable full trace.
24
+
25
+ `raise:` Set this option to false to disable the raising of errors.
26
+
27
+ `rails_logger:` Set the level for debug and colored output.
28
+
29
+ Example usage:
30
+
31
+ ```ruby
32
+ # default values
33
+
34
+ DeprecatedAttributes.configure do |config|
35
+ config.enable = true
36
+ config.full_trace = false
37
+ config.raise = false
38
+ config.rails_logger = {
39
+ level: :debug,
40
+ color: true
41
+ }
42
+ end
43
+
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ **In your model:**
49
+
50
+ ```ruby
51
+
52
+ class User < ActiveRecord::Base
53
+ include DeprecatedAttributes
54
+
55
+ # this works
56
+ deprecated_attribute :first_name, message: "name was deprecated in favor of name"
57
+
58
+ # you can wrap two or more attributes in an array
59
+ deprecated_attribute [:address_1, :address_2], message: "no longer need for addressess"
60
+ # or
61
+ deprecated_attribute %i[address_1 address_2], message: "no longer need for addressess"
62
+
63
+ # this wont work
64
+ deprecated_attribute :address_1, :address_2, message: "no longer need for addressess"
65
+ end
66
+
67
+ ```
68
+
69
+ **Examples**:
70
+
71
+ > User.deprecated_attributes
72
+ => [:first_name]
73
+
74
+ > User.deprecated_attribute? :first_name
75
+ => true
76
+
77
+ > user = User.first
78
+ > user.first_name
79
+
80
+ => DEPRECATION WARNING: `first_name` is deprecated. Was called on User with args: []
81
+ => DEPRECATION DETAILS: first_name was deprecated in favor of name
82
+
83
+ # if DeprecatedAttributes.configuration.raise = true
84
+ => DeprecatedAttributes::DeprecatedAttributeError: DeprecatedAttributes::DeprecatedAttributeError
85
+
86
+
87
+
88
+
89
+ ## Development
90
+
91
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+
93
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
94
+
95
+ ## Contributing
96
+
97
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aromaron/deprecated_attributes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/aromaron/deprecated_attributes/blob/main/CODE_OF_CONDUCT.md).
98
+
99
+ ## License
100
+
101
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
102
+
103
+ ## Code of Conduct
104
+
105
+ Everyone interacting in the DeprecatedAttributes project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aromaron/deprecated_attributes/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record"
4
+ require "deprecated_attributes"
5
+
6
+ # rubocop:disable Style/ClassAndModuleChildren
7
+ # Override ActiveRecord arttribute_methods
8
+ class ActiveRecord::Base
9
+ include DeprecatedAttributes
10
+
11
+ def attribute_names
12
+ self.class.attribute_names.reject { |attr| self.class.deprecated_attributes.include?(attr.to_sym) }
13
+ end
14
+
15
+ def serializable_hash(options = {})
16
+ options = {} if options.nil?
17
+
18
+ options[:only] = attributes.keys.map(&:to_sym) - (self.class.deprecated_attributes || []).map(&:to_sym)
19
+
20
+ super(options)
21
+ end
22
+
23
+ def attribute_for_inspect(attr_name)
24
+ return super unless self.class.deprecated_attributes.include?(attr_name.to_sym)
25
+
26
+ attr_name = attr_name.to_s
27
+ attr_name = self.class.attribute_aliases[attr_name] || attr_name
28
+ last_value = _read_attribute(attr_name)
29
+
30
+ value = "DEPRECATED with value: #{last_value}"
31
+
32
+ format_for_inspect(attr_name, value)
33
+ end
34
+ end
35
+ # rubocop:enable Style/ClassAndModuleChildren
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configuration for DeprecatedAttributes
4
+ module DeprecatedAttributes
5
+ def self.configuration
6
+ @configuration ||= Configuration.new
7
+ end
8
+
9
+ # Allows configuration options to be set using a block.
10
+ def self.configure
11
+ yield(configuration)
12
+ end
13
+
14
+ # Resets current configuration to default values.
15
+ def self.reset
16
+ @configuration = Configuration.new
17
+ end
18
+
19
+ # Configuration class to define log and error preferences.
20
+ # Enable: whether or not to show logs
21
+ # Full Trace: show full trace of error
22
+ # Raise: To raise a DeprecatedAttributeError
23
+ # Rails Logger: To customize logger output
24
+ class Configuration
25
+ attr_accessor :enable, :full_trace, :raise, :rails_logger
26
+
27
+ def initialize
28
+ @enable = true
29
+ @full_trace = false
30
+ @raise = false
31
+ @rails_logger = default_rails_logger_config
32
+ end
33
+
34
+ private
35
+
36
+ def default_rails_logger_config
37
+ {level: :debug, color: true}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeprecatedAttributes
4
+ class DeprecatedAttributeError < StandardError; end
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DeprecatedAttributes
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_record"
5
+
6
+ require_relative "deprecated_attributes/version"
7
+ require_relative "deprecated_attributes/errors"
8
+ require_relative "deprecated_attributes/configuration"
9
+ require_relative "deprecated_attributes/active_record_extension"
10
+
11
+ require "notifiers/rails_logger"
12
+
13
+ # Active Record Deprecated Attribute Module
14
+ module DeprecatedAttributes
15
+ extend ActiveSupport::Concern
16
+
17
+ included do
18
+ class_attribute :_deprecated_attributes, instance_writer: false
19
+ end
20
+
21
+ def self.included(base)
22
+ base.extend ClassMethods
23
+ end
24
+
25
+ # Class Methods Definitions
26
+ module ClassMethods
27
+ # Safely marks an attribute as deprecated (non-destructive).
28
+ def deprecated_attribute(attrs = [], message: nil)
29
+ # pre-initialize any deprecated attributes
30
+ attributes = Set.new(ensure_array(attrs).compact)
31
+ @deprecated_attributes ||= Set.new
32
+
33
+ # pre-initialize a new instance of our ActiveRecord model from `attributes`
34
+ new(attributes.zip(attributes.map {}).to_h) if defined?(ActiveRecord) && ancestors.include?(ActiveRecord::Base)
35
+
36
+ # Taking the difference of the two sets ensures we don't deprecate the same attribute more than once
37
+ (attributes - deprecated_attributes).each do |attribute|
38
+ override_deprecated_attribute(attribute, message)
39
+ end
40
+
41
+ @deprecated_attributes += attributes
42
+ end
43
+
44
+ # return a list of all deprecated attributes for this class
45
+ def deprecated_attributes
46
+ (@deprecated_attributes || Set.new).to_a
47
+ end
48
+
49
+ # check if the passed attribute is defined
50
+ def deprecated_attribute?(attribute)
51
+ @deprecated_attributes.include?(attribute)
52
+ end
53
+
54
+ # clears deprecated attributes for this class
55
+ def clear_deprecated_attributes!
56
+ @deprecated_attributes.clear
57
+ end
58
+
59
+ def accessors
60
+ ["", "=", "_before_type_cast", "?", "_changed?", "_change", "_will_change!", "_was"]
61
+ end
62
+
63
+ # Wrap the original attribute method with appropriate notification and errors
64
+ def override_deprecated_attribute(attribute, message)
65
+ accessors.each do |term|
66
+ original_attribute_method = instance_method("#{attribute}#{term}")
67
+ define_method("#{attribute}#{term}") do |*args|
68
+ backtrace = ActiveSupport::BacktraceCleaner.new.clean(caller)
69
+ self.class.notify_deprecated_attribute(klass: self.class, attribute: attribute,
70
+ args: args, backtrace: backtrace, msg: message)
71
+ self.class.raise_deprecated_attribute
72
+
73
+ original_attribute_method.bind_call(self, *args)
74
+ end
75
+ end
76
+ end
77
+
78
+ # Dispatch a notification to the the Rails Logger
79
+ def notify_deprecated_attribute(payload)
80
+ ActiveSupport::Notifications.instrument("deprecated_attributes.active_record", payload)
81
+ end
82
+
83
+ # Raises a DeprecatedAttributeError if DeprecatedAttributes is configurated to do so.
84
+ def raise_deprecated_attribute
85
+ raise DeprecatedAttributeError if DeprecatedAttributes.configuration.raise
86
+ end
87
+
88
+ private
89
+
90
+ def ensure_array(value)
91
+ value.is_a?(Array) ? value : [value]
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Extend Rails logger
4
+ module DeprecatedAttributes
5
+ # Log Subscriber
6
+ class LogSubscriber < ActiveSupport::LogSubscriber
7
+ def logger_config
8
+ DeprecatedAttributes.configuration.rails_logger || {}
9
+ end
10
+
11
+ def log_color(text, color, bold: true)
12
+ logger_config[:color] ? color(text, color, bold) : text
13
+ end
14
+
15
+ def log_method(msg, level = :info)
16
+ log_level = %i[debug info warn error fatal].include?(level) ? level : :unknown
17
+ send(log_level, msg)
18
+ end
19
+
20
+ def format_message(payload)
21
+ title = log_color("DEPRECATION WARNING:", YELLOW)
22
+ klass_str = log_color(payload[:klass], CYAN)
23
+ attr_str = log_color(payload[:attribute], BLUE)
24
+ args_str = log_color(payload[:args], MAGENTA)
25
+ msg_str = payload[:msg] ? "#{log_color("DEPRECATION DETAILS:", YELLOW)} #{log_color(payload[:msg], MAGENTA)}" : ""
26
+
27
+ backtrace = payload[:backtrace].join("\n")
28
+ ["\n#{title} `#{attr_str}` is deprecated. Was called on #{klass_str} with args: #{args_str}\n#{msg_str}",
29
+ backtrace].join("\n")
30
+ end
31
+
32
+ def deprecated_attributes(event)
33
+ deprecation_message = format_message(event.payload)
34
+
35
+ log_method(deprecation_message, logger_config[:level])
36
+ end
37
+
38
+ def logger
39
+ ActiveRecord::Base.logger
40
+ end
41
+ end
42
+ end
43
+
44
+ DeprecatedAttributes::LogSubscriber.attach_to :active_record if DeprecatedAttributes.configuration.enable
data/sig/arda.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module DeprecatedAttributes
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deprecated_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nora Alvarado
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-03-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 7.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 7.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.14.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.14.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: standard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.3'
111
+ description: DeprecatedAttributes provides a straightforward and unobtrusive method
112
+ for flagging deprecated attributes in your model. When these attributes are accessed,
113
+ a warning message will be logged along with a trace of where the deprecated attribute
114
+ was called. Additionally, an exception can be raised if desired.
115
+ email:
116
+ - nora.alvarado@hey.com
117
+ executables: []
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".rspec"
122
+ - ".rubocop.yml"
123
+ - ".standard.yml"
124
+ - CHANGELOG.md
125
+ - CODE_OF_CONDUCT.md
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - README.md
130
+ - Rakefile
131
+ - lib/deprecated_attributes.rb
132
+ - lib/deprecated_attributes/active_record_extension.rb
133
+ - lib/deprecated_attributes/configuration.rb
134
+ - lib/deprecated_attributes/errors.rb
135
+ - lib/deprecated_attributes/version.rb
136
+ - lib/notifiers/rails_logger.rb
137
+ - sig/arda.rbs
138
+ homepage: https://github.com/aromaron/deprecated_attributes
139
+ licenses:
140
+ - MIT
141
+ metadata:
142
+ homepage_uri: https://example.com
143
+ source_code_uri: https://github.com/aromaron/deprecated_attributes
144
+ changelog_uri: https://github.com/aromaron/deprecated_attributes/blob/main/CHANGELOG.md
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: 3.0.0
154
+ required_rubygems_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubygems_version: 3.2.33
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: DeprecatedAttributes is library to deprecate attributes
164
+ test_files: []