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 custom GTINs #29

Merged
merged 7 commits into from
Sep 28, 2022
Merged

Commits on Jun 23, 2022

  1. Support custom GTINs

    This refactors GTIN handler class lookup so it can be extended without
    monkeypatching. Developers can add/remove classes in
    `BarcodeValidation::GTIN.gtin_classes` to control which class wraps a
    GTIN. The use case I need this for is internall dummy GTINs that are
    longer than any of the standard ones.
    
    The Readme is updated to describe the feature.
    Narnach committed Jun 23, 2022
    Configuration menu
    Copy the full SHA
    a0d0e9b View commit details
    Browse the repository at this point in the history

Commits on Sep 19, 2022

  1. Implemented GTIN::Base.prioritize_before

    This is part of marketplacer#29, which makes it easier to implement custom GTINs as
    a user of this library. The first implementation in a0d0e9b worked, but
    required the user to directly manipulate registered classes inside an
    Array. As @beet pointed out, it's better to not expose implementation
    details like that and look for a more elegant interface.
    
    This commit changes the implementation by replacing `gtin_classes` with
    `prioritized_gtin_classes` and adding a note that this is a private API.
    Any subclass of `GTIN::Base` will be automatically appended to this list.
    
    The user gets two tools directly inside `GTIN::Base`:
    
    - `prioritize_before (other_class)`: moves this class to directly in
      front of the other class. This allows this class to be asked if it
      `handles?` a GTIN before the other class.
    - `abstract_class`: lets a class remove itself from the list of classes
      that are asked if they handle a GTIN.
    
    There are tests for both the implementation details and functionality.
    Narnach committed Sep 19, 2022
    Configuration menu
    Copy the full SHA
    cd32ab6 View commit details
    Browse the repository at this point in the history

Commits on Sep 20, 2022

  1. Refactor: GTIN#remove_gtin_class handles delete behavior

    The goal is to make `prioritized_gtin_classes` private data and only
    expose methods that have interactions with it. Replacing #delete
    behavior from GTIN::Base with calls to this new method is one step in
    the right direction.
    Narnach committed Sep 20, 2022
    Configuration menu
    Copy the full SHA
    20719f3 View commit details
    Browse the repository at this point in the history
  2. Refactor: GTIN handles internal logic of appending a GTIN class

    This is another small step towards making GTIN::Base not manipulate the
    internals of `GTIN.prioritized_gtin_classes`, but letting GTIN handle
    that by itself.
    Narnach committed Sep 20, 2022
    Configuration menu
    Copy the full SHA
    5a24eb6 View commit details
    Browse the repository at this point in the history
  3. Refactor: GTIN::Base.prioritize_before does not touch GTIN internals

    Manipulating `GTIN.prioritized_gtin_classes` now only happens through
    helper methods on GTIN, theoretically allowing the list itself to become
    private.
    Narnach committed Sep 20, 2022
    Configuration menu
    Copy the full SHA
    a324144 View commit details
    Browse the repository at this point in the history
  4. Doc: document BarcodeValidation::GTIN

    Having a few lines to outline the purpose of a class and its neighbours
    tends to help understanding and exploration of a codebase.
    Narnach committed Sep 20, 2022
    Configuration menu
    Copy the full SHA
    91d8c97 View commit details
    Browse the repository at this point in the history
  5. GTIN.prioritized_gtin_classes is private

    The only thing that still depended on it being public were the tests for
    functionality that manipulated the list. The tests have been overhauled
    to rely more on asserting behavior than internal state.
    Narnach committed Sep 20, 2022
    Configuration menu
    Copy the full SHA
    284c50d View commit details
    Browse the repository at this point in the history