Skip to content

Commit

Permalink
docs: simplify transform example
Browse files Browse the repository at this point in the history
Signed-off-by: saxtondrey <[email protected]>
  • Loading branch information
SaxtonDrey committed Jun 18, 2024
1 parent 0068129 commit 3caf726
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 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
# which is an array of some columns
end

def dynamic_fields
custom_columns.each_with_object({}){|col,result| result[col] = self.send(col)}
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 3caf726

Please sign in to comment.