Skip to content

Commit

Permalink
Merge pull request #415 from SaxtonDrey/doc-update-readme-transform-s…
Browse files Browse the repository at this point in the history
…ection

docs: update Transform examples
  • Loading branch information
lessthanjacob authored Jun 20, 2024
2 parents 2a6fb3d + 3caf726 commit 8a94b25
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,20 +773,31 @@ Create a Transform class extending from `Blueprinter::Transformer`

```ruby
class DynamicFieldTransformer < Blueprinter::Transformer
def transform(hash, object, options)
def transform(hash, object, _options)
hash.merge!(object.dynamic_fields)
end
end
```

```ruby
class User
def custom_columns
self.dynamic_fields #which is an array of some columns
end

def custom_fields
custom_columns.each_with_object({}){|col,result| result[col] = self.send(col)}
def dynamic_fields
case role
when :admin
{
employer: employer,
time_in_role: determine_time_in role
}
when :maintainer
{
label: label,
settings: generate_settings_hash
}
when :read_only
{
last_login_at: last_login_at
}
end
end
end
```
Expand Down

0 comments on commit 8a94b25

Please sign in to comment.