Project

sunsetter

0.0
The project is in a healthy, maintained state
Sunsetter provides a simple way to mark Mongoid fields as deprecated and show warning messages when they are accessed.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 2.0
~> 5.0
~> 0.5.0
~> 13.0
~> 1.0

Runtime

>= 7.0.0
 Project Readme

Sunsetter

Gem Version Build Status

A Ruby gem that helps you mark Mongoid model fields as deprecated and display warning messages when they are used.

Installation

Add this line to your application's Gemfile:

gem 'sunsetter'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install sunsetter

Usage

To mark a field as deprecated in your Mongoid model:

class User
  include Mongoid::Document
  include Sunsetter

  field :old_name
  field :new_name
  deprecate_field :old_name
end

When the deprecated field is accessed, you'll see warning messages like this:

[SUNSETTER] User#old_name is deprecated and will be removed in a future version.
[SUNSETTER] Called from: app/models/user.rb:42:in `some_method'
[SUNSETTER] Please update your code to use alternative methods.

Customizing Log Output

You can customize how deprecation warnings are logged:

# In Rails, you might want to use Rails.logger
Sunsetter.configure do |config|
  config.logger = ->(message) { Rails.logger.warn(message) }
end

# Or use your own logger
Sunsetter.configure do |config|
  config.logger = ->(message) { MyLogger.warn(message) }
end

# Or suppress warnings entirely
Sunsetter.configure do |config|
  config.logger = ->(message) { } # no-op
end

Features

  • Displays warnings when deprecated fields are accessed
  • Shows caller information (file name and line number)
  • Prevents usage in non-Mongoid::Document models
  • Implementation is independent of include order
  • Customizable logging behavior

Development

Setup

$ git clone https://github.com/ryoh827/sunsetter.git
$ cd sunsetter
$ bundle install

Running Tests

$ bundle exec ruby test/test_sunsetter.rb

License

The gem is available as open source under the terms of the MIT License.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request