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

Support procs for required_if; add present_if #115

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Mar 20, 2015

  1. Support procs in required_if option

    These were supported in AttributeResolver, but not in Attribute
    itself. The proc will receive one argument, which is the loaded object.
    
    Signed-off-by: Sean McGivern <[email protected]>
    Sean McGivern committed Mar 20, 2015
    Configuration menu
    Copy the full SHA
    59965f3 View commit details
    Browse the repository at this point in the history
  2. Add present_if option

    When dumping a model, each attribute will be replaced with nil if it has
    a present_if condition and that condition is not met. The allowed
    conditions are the same as for required_if:
    
    * A string key, which passes if that key's value is not nil.
    * A one-item hash, whose key is the path in the object, and whose value
      is any ===-compatible object (string, regex, proc, etc.).
    * A proc, which is passed the object.
    
    Like required_if, this cannot be used in conjunction with the required
    option. It can be used with the required_if option, but it should only
    be so in a way that they are compatible (for instance, if both have the
    same condition, then the attribute will only be present when it is
    required).
    
    Signed-off-by: Sean McGivern <[email protected]>
    Sean McGivern committed Mar 20, 2015
    Configuration menu
    Copy the full SHA
    09416d8 View commit details
    Browse the repository at this point in the history