sunsetter 0.1.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 37ced06e05303260aca17b9069cbf72def556def83b02c1cd5891b799b15a59e
4
+ data.tar.gz: e4fb09c5a8cb291a846d2de0933fc80ec6f37706fb826c66b4b30148fad41348
5
+ SHA512:
6
+ metadata.gz: c81149f87e7d951873bc5de6e4fda8db50c18c4b5204e75358867d12af197f5f1d0144fc0a80ad81180846e7f49f5219db08a550f9bd4fa6520a0fba8d630780
7
+ data.tar.gz: 93699a34b63a885c8ea55241c50a74d8f7d5caa2dca48b6fef0babffc74fc688301f91bc7bbf70ddb3db7bd634669c3af7cfc95a4df64ff290b4679ddfdd7199
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ parallel: true
2
+ format: progress
3
+ fix: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [v0.1.2]
9
+
10
+ ### Added
11
+ - Initial release of Sunsetter gem
12
+ - Support for marking Mongoid fields as deprecated
13
+ - Customizable deprecation warning messages
14
+ - Logger configuration support
15
+ - Mongoid model validation
16
+
17
+ ## [Unreleased]
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "mongoid"
4
+ gem "minitest"
5
+ gem "ostruct"
6
+
7
+ group :development do
8
+ gem "standard", "~> 1.0"
9
+ gem "rake", "~> 13.0"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activemodel (8.0.2)
5
+ activesupport (= 8.0.2)
6
+ activesupport (8.0.2)
7
+ base64
8
+ benchmark (>= 0.3)
9
+ bigdecimal
10
+ concurrent-ruby (~> 1.0, >= 1.3.1)
11
+ connection_pool (>= 2.2.5)
12
+ drb
13
+ i18n (>= 1.6, < 2)
14
+ logger (>= 1.4.2)
15
+ minitest (>= 5.1)
16
+ securerandom (>= 0.3)
17
+ tzinfo (~> 2.0, >= 2.0.5)
18
+ uri (>= 0.13.1)
19
+ ast (2.4.3)
20
+ base64 (0.2.0)
21
+ benchmark (0.4.0)
22
+ bigdecimal (3.1.9)
23
+ bson (5.0.2)
24
+ concurrent-ruby (1.3.5)
25
+ connection_pool (2.5.3)
26
+ drb (2.2.1)
27
+ i18n (1.14.7)
28
+ concurrent-ruby (~> 1.0)
29
+ json (2.10.2)
30
+ language_server-protocol (3.17.0.4)
31
+ lint_roller (1.1.0)
32
+ logger (1.7.0)
33
+ minitest (5.25.5)
34
+ mongo (2.21.1)
35
+ base64
36
+ bson (>= 4.14.1, < 6.0.0)
37
+ mongoid (9.0.6)
38
+ activemodel (>= 5.1, < 8.1, != 7.0.0)
39
+ concurrent-ruby (>= 1.0.5, < 2.0)
40
+ mongo (>= 2.18.0, < 3.0.0)
41
+ ostruct (0.6.1)
42
+ parallel (1.26.3)
43
+ parser (3.3.7.3)
44
+ ast (~> 2.4.1)
45
+ racc
46
+ racc (1.8.1)
47
+ rainbow (3.1.1)
48
+ rake (13.2.1)
49
+ regexp_parser (2.10.0)
50
+ rubocop (1.73.2)
51
+ json (~> 2.3)
52
+ language_server-protocol (~> 3.17.0.2)
53
+ lint_roller (~> 1.1.0)
54
+ parallel (~> 1.10)
55
+ parser (>= 3.3.0.2)
56
+ rainbow (>= 2.2.2, < 4.0)
57
+ regexp_parser (>= 2.9.3, < 3.0)
58
+ rubocop-ast (>= 1.38.0, < 2.0)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (>= 2.4.0, < 4.0)
61
+ rubocop-ast (1.42.0)
62
+ parser (>= 3.3.7.2)
63
+ rubocop-performance (1.24.0)
64
+ lint_roller (~> 1.1)
65
+ rubocop (>= 1.72.1, < 2.0)
66
+ rubocop-ast (>= 1.38.0, < 2.0)
67
+ ruby-progressbar (1.13.0)
68
+ securerandom (0.4.1)
69
+ standard (1.47.0)
70
+ language_server-protocol (~> 3.17.0.2)
71
+ lint_roller (~> 1.0)
72
+ rubocop (~> 1.73.0)
73
+ standard-custom (~> 1.0.0)
74
+ standard-performance (~> 1.7)
75
+ standard-custom (1.0.2)
76
+ lint_roller (~> 1.0)
77
+ rubocop (~> 1.50)
78
+ standard-performance (1.7.0)
79
+ lint_roller (~> 1.1)
80
+ rubocop-performance (~> 1.24.0)
81
+ tzinfo (2.0.6)
82
+ concurrent-ruby (~> 1.0)
83
+ unicode-display_width (3.1.4)
84
+ unicode-emoji (~> 4.0, >= 4.0.4)
85
+ unicode-emoji (4.0.4)
86
+ uri (1.0.3)
87
+
88
+ PLATFORMS
89
+ arm64-darwin-24
90
+ ruby
91
+
92
+ DEPENDENCIES
93
+ minitest
94
+ mongoid
95
+ ostruct
96
+ rake (~> 13.0)
97
+ standard (~> 1.0)
98
+
99
+ BUNDLED WITH
100
+ 2.6.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ryoh827
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # Sunsetter
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/sunsetter.svg)](https://badge.fury.io/rb/sunsetter)
4
+ [![Build Status](https://github.com/ryoh827/sunsetter/actions/workflows/ci.yml/badge.svg)](https://github.com/ryoh827/sunsetter/actions/workflows/ci.yml)
5
+
6
+ A Ruby gem that helps you mark Mongoid model fields as deprecated and display warning messages when they are used.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'sunsetter'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```bash
19
+ $ bundle install
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```bash
25
+ $ gem install sunsetter
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ To mark a field as deprecated in your Mongoid model:
31
+
32
+ ```ruby
33
+ class User
34
+ include Mongoid::Document
35
+ include Sunsetter
36
+
37
+ field :old_name
38
+ field :new_name
39
+ deprecate_field :old_name
40
+ end
41
+ ```
42
+
43
+ When the deprecated field is accessed, you'll see warning messages like this:
44
+
45
+ ```
46
+ [SUNSETTER] User#old_name is deprecated and will be removed in a future version.
47
+ [SUNSETTER] Called from: app/models/user.rb:42:in `some_method'
48
+ [SUNSETTER] Please update your code to use alternative methods.
49
+ ```
50
+
51
+ ### Customizing Log Output
52
+
53
+ You can customize how deprecation warnings are logged:
54
+
55
+ ```ruby
56
+ # In Rails, you might want to use Rails.logger
57
+ Sunsetter.configure do |config|
58
+ config.logger = ->(message) { Rails.logger.warn(message) }
59
+ end
60
+
61
+ # Or use your own logger
62
+ Sunsetter.configure do |config|
63
+ config.logger = ->(message) { MyLogger.warn(message) }
64
+ end
65
+
66
+ # Or suppress warnings entirely
67
+ Sunsetter.configure do |config|
68
+ config.logger = ->(message) { } # no-op
69
+ end
70
+ ```
71
+
72
+ ## Features
73
+
74
+ - Displays warnings when deprecated fields are accessed
75
+ - Shows caller information (file name and line number)
76
+ - Prevents usage in non-Mongoid::Document models
77
+ - Implementation is independent of include order
78
+ - Customizable logging behavior
79
+
80
+ ## Development
81
+
82
+ ### Setup
83
+
84
+ ```bash
85
+ $ git clone https://github.com/ryoh827/sunsetter.git
86
+ $ cd sunsetter
87
+ $ bundle install
88
+ ```
89
+
90
+ ### Running Tests
91
+
92
+ ```bash
93
+ $ bundle exec ruby test/test_sunsetter.rb
94
+ ```
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
99
+
100
+ ## Contributing
101
+
102
+ 1. Fork it
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[test standard]
@@ -0,0 +1,3 @@
1
+ module Sunsetter
2
+ VERSION = "0.1.2"
3
+ end
data/lib/sunsetter.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Sunsetter
2
+ class << self
3
+ attr_accessor :logger
4
+
5
+ def configure
6
+ yield self
7
+ end
8
+ end
9
+
10
+ # デフォルトのロガー
11
+ self.logger = ->(message) { warn message }
12
+
13
+ def self.included(base)
14
+ base.extend(ClassMethods)
15
+ end
16
+
17
+ module ClassMethods
18
+ def deprecate_field(*field_names)
19
+ unless include?(Mongoid::Document)
20
+ raise "Sunsetter can only be used in Mongoid::Document models"
21
+ end
22
+
23
+ field_names.each do |field_name|
24
+ original_method = instance_method(field_name)
25
+
26
+ define_method(field_name) do |*args, &block|
27
+ caller_info = caller(1..1).first
28
+ Sunsetter.logger.call("[SUNSETTER] #{self.class.name}##{field_name} is deprecated and will be removed in a future version.")
29
+ Sunsetter.logger.call("[SUNSETTER] Called from: #{caller_info}")
30
+ Sunsetter.logger.call("[SUNSETTER] Please update your code to use alternative methods.")
31
+ original_method.bind_call(self, *args, &block)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
data/mise.toml ADDED
@@ -0,0 +1,2 @@
1
+ [tools]
2
+ ruby = "3.4"
data/sunsetter.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/sunsetter/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sunsetter"
7
+ spec.version = Sunsetter::VERSION
8
+ spec.authors = ["ryoh827"]
9
+ spec.email = ["ryoh827.dev@gmail.com"]
10
+
11
+
12
+ spec.summary = "A gem to mark Mongoid fields as deprecated with warning messages"
13
+ spec.description = "Sunsetter provides a simple way to mark Mongoid fields as deprecated and show warning messages when they are accessed."
14
+ spec.homepage = "https://github.com/ryoh827/sunsetter"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 3.2.0"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) || f.match(/\.gem$/)
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "mongoid", ">= 7.0.0"
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ spec.add_development_dependency "ostruct", "~> 0.5.0"
34
+ spec.add_development_dependency "standard", "~> 1.0"
35
+ spec.add_development_dependency "rake", "~> 13.0"
36
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunsetter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - ryoh827
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-05-04 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: mongoid
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 7.0.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 7.0.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: minitest
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '5.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: ostruct
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 0.5.0
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.5.0
68
+ - !ruby/object:Gem::Dependency
69
+ name: standard
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rake
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '13.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '13.0'
96
+ description: Sunsetter provides a simple way to mark Mongoid fields as deprecated
97
+ and show warning messages when they are accessed.
98
+ email:
99
+ - ryoh827.dev@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".standard.yml"
105
+ - CHANGELOG.md
106
+ - Gemfile
107
+ - Gemfile.lock
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - lib/sunsetter.rb
112
+ - lib/sunsetter/version.rb
113
+ - mise.toml
114
+ - sunsetter.gemspec
115
+ homepage: https://github.com/ryoh827/sunsetter
116
+ licenses:
117
+ - MIT
118
+ metadata:
119
+ homepage_uri: https://github.com/ryoh827/sunsetter
120
+ source_code_uri: https://github.com/ryoh827/sunsetter
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 3.2.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.6.2
136
+ specification_version: 4
137
+ summary: A gem to mark Mongoid fields as deprecated with warning messages
138
+ test_files: []