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

An idea to combat model pollution #719

Merged
merged 1 commit into from
Jun 20, 2016
Merged

Commits on Jun 6, 2016

  1. An idea to combat model pollution

    Problem
    -------
    
    `has_paper_trail` adds too many methods to the ActiveRecord model.
    
    > If I'm counting correctly, installing the paper_trail gem adds 36 instance
    > methods and 10 class methods to all of your active record models. Of those
    > 46, 13 have a prefix, either "pt_" or "paper_trail_". I don't know what the
    > best way to deal with this is. Ideally, we'd add far fewer methods to
    > people's models. If we were able to add fewer methods to models, then I
    > wouldn't mind prefixing all of them.
    > #703
    
    Solution
    --------
    
    Add only two methods to the AR model.
    
    1. An instance method `#paper_trail`
    2. A class method `.paper_trail`
    
    The instance method would return a `RecordTrail` and the class method would
    return a `ClassTrail`. Those names are totally up for debate.
    
    Advantages
    ----------
    
    - Plain ruby, easy to understand
    - Adding new methods to e.g. the `RecordTrail` does not add any methods to
      the AR model.
    - Methods privacy is more strongly enforced.
    - Enables isolated testing of e.g. `RecordTrail`; it can be constructed with a
      mock AR instance.
    
    Disadvantages
    -------------
    
    - Two new classes, though they are simple.
    jaredbeck committed Jun 6, 2016
    Configuration menu
    Copy the full SHA
    ad3806f View commit details
    Browse the repository at this point in the history