codenoble / cache-crispies

Speedy Rails JSON serialization with built-in caching
MIT License
156 stars 16 forks source link

Feature: Adding option to pass method as symbol to show_if #36

Closed uxxman closed 3 years ago

uxxman commented 3 years ago

Related to #31

Before:

class SomeSerializer < CacheCrispies::Base
  show_if -> (model, options) { model.published? && options[:current_user].admin? && options[:current_user].active? && options[:current_user].id == model.user_id } do
    serialize :published_at
  end
end

After:

class SomeSerializer < CacheCrispies::Base
  show_if :include_published_at? do
    serialize :published_at
  end

  def include_published_at?
    model.published? &&
      options[:current_user].admin?  &&
      options[:current_user].active? &&
      options[:current_user].id == model.user_id
  end
end
uxxman commented 3 years ago

@adamcrown any thoughts on this?

adamcrown commented 3 years ago

Hi @uxxman . So sorry it's taken so long for me to get to this. I didn't realize I was getting so far behind.

I think this change looks good! It's a nice simplification. Thanks for submitting it and putting the work into the Codeclimate fix too!

adamcrown commented 3 years ago

FYI, I just pushed version 1.3.0 which includes this change.

uxxman commented 3 years ago

@adamcrown thank you :) can finally remove our private fork and switch back to the official gem :)