diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ff9bec..05a29d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] -Nothing yet. +### Added +- Include `#decorated` method in `ActiveRecord::Base` ## [1.4.0] - 2023-11-09 ### Changed diff --git a/lib/dekorator/rails/record.rb b/lib/dekorator/rails/record.rb new file mode 100644 index 0000000..ff513ed --- /dev/null +++ b/lib/dekorator/rails/record.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "active_support/concern" + +module Dekorator + module Record + def decorated + @decorated ||= Dekorator::Base.decorate(self) + end + end +end diff --git a/lib/dekorator/railtie.rb b/lib/dekorator/railtie.rb index 472c52b..a9f55f9 100644 --- a/lib/dekorator/railtie.rb +++ b/lib/dekorator/railtie.rb @@ -2,6 +2,7 @@ module Dekorator require "dekorator/rails/controller" + require "dekorator/rails/record" class Railtie < ::Rails::Railtie rake_tasks do @@ -10,6 +11,7 @@ class Railtie < ::Rails::Railtie config.to_prepare do |_app| ActionController::Base.include Dekorator::Controller + ActiveRecord::Base.include Dekorator::Record end end end