Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to store metadata #60

Closed
ghost opened this issue Feb 6, 2018 · 4 comments
Closed

Add support to store metadata #60

ghost opened this issue Feb 6, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 6, 2018

Logidze is really awesome but it can't replace papertrail in a project I'm working on.
This kind of stuff does not belong to the resource itself, it would be more pleasant to store it alongside the log.

# application_controller.rb
def info_for_paper_trail
  { ip: request.remote_ip }
end

# model.rb
attr_accessor :comment
[...]
has_paper_trail meta: { reason: comment }
@anand180
Copy link

I'm running into the same limitation on my end. My work-around at the moment is to use responsible_id as it can take an arbitrary string as its value

# store meta
Logidze.with_responsible({test: 123}.to_json) do
  Model.update(...)
end

# retrieve meta
meta = JSON.parse(log_data.responsible_id)

However, a better API would be something like

# store meta
Logidze.with_meta({test: 123}) do
  Model.update(...)
end

# retrieve meta
meta = log_data.meta # => {test: 123}

@anand180
Copy link

If there is some consensus on what the API should look like, I don't mind helping out with the implementation.

@palkan
Copy link
Owner

palkan commented Mar 26, 2018

I like the proposed API (with_meta); we can implement it the same way as with_responsible.

record = Model.find(123)

Logidze.with_meta(test: 123) do
  record.update(attrs)
end

record.reload

# log_meta is equal to log_data.meta
meta = record.log_meta # => { "test" => 123 }

Note that the resulted Hash would have stringified keys (due to JSON encoding/decoding).

Feel free to propose a PR with the implementation!

DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 14, 2018
DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 22, 2018
DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 23, 2018
DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 23, 2018
DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 23, 2018
DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 28, 2018
DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 28, 2018
DmitryTsepelev added a commit to DmitryTsepelev/logidze that referenced this issue Aug 28, 2018
@palkan
Copy link
Owner

palkan commented Aug 29, 2018

Closed by #79 and released as 0.7.0

@palkan palkan closed this as completed Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants