Skip to content

Commit

Permalink
feat: include #decorated method in ActiveRecord::Base
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Mar 6, 2024
1 parent b037876 commit 4fec4f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/dekorator/rails/record.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/dekorator/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Dekorator
require "dekorator/rails/controller"
require "dekorator/rails/record"

class Railtie < ::Rails::Railtie
rake_tasks do
Expand All @@ -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

0 comments on commit 4fec4f7

Please sign in to comment.