Skip to content

Commit

Permalink
refactor: rename generated method by .decorates_association
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-brousse committed Nov 6, 2023
1 parent fd414f7 commit feac76d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
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
### Changed
- **Breaking** `.decorates_association` now generate `#decorated_[ASSOCIATION_NAME]` instead `#[ASSOCIATION_NAME]` ([#48](https://github.com/komposable/dekorator/pull/48))

## [1.3.0] - 2023-11-06
### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ class PostDecorator < ApplicationDecorator
end
```

In this example, `UserDecorator#posts` will be decorated.
In this example, `UserDecorator#posts` will be decorated as `#decorated_posts`.

```ruby
decorated_user = decorate(User.first)
decorated_user # => UserDecorator
decorated_user.posts.first # => PostDecorator
decorated_user.decorated_posts.first # => PostDecorator
```

### Custom decorator
Expand Down Expand Up @@ -148,7 +148,7 @@ end

decorated_user = decorate(User.first)
decorated_user # => UserDecorator
decorated_user.posts.first # => ArticleDecorator
decorated_user.decorated_posts.first # => ArticleDecorator
```

## Compatibility
Expand Down
2 changes: 1 addition & 1 deletion lib/dekorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def decorate(object_or_enumerable, with: nil)
def decorates_association(relation_name, with: :__guess__)
relation_name = relation_name.to_sym

define_method(relation_name) do
define_method(:"decorated_#{relation_name}") do
@_decorated_associations[relation_name] ||= decorate(__getobj__.public_send(relation_name), with: with)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/dekorator_base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
end

describe "self#decorates_association" do
it { expect(decorated_post_with_comments.comments).to all(be_a(CommentDecorator)) }
it { expect(decorated_post_with_comments.decorated_comments).to all(be_a(CommentDecorator)) }
end

describe "self#base_class" do
Expand Down

0 comments on commit feac76d

Please sign in to comment.