active_record-associated_object 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +42 -4
- data/active_record-associated_object.gemspec +0 -5
- data/lib/active_record/associated_object/railtie.rb +9 -5
- data/lib/active_record/associated_object/version.rb +1 -1
- data/lib/active_record/associated_object.rb +6 -5
- metadata +2 -16
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 183e19260b1d449e28b760db3736cc6ca82506064c24c24cec9ecf4333d4b441
         | 
| 4 | 
            +
              data.tar.gz: 01fc12b34d5eaee9ebb1fccfe9183287022e6a6e314a98739867bf94061fde29
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 1439d66acf12abe1a26cddebefe0900826a04afc85be171d3622a665810c2ecce7e849098fa3a901aef84d99ddbfd16f33f455c8ad1822e1009f938a8734c0b5
         | 
| 7 | 
            +
              data.tar.gz: a750d3c644db9b92a097b5fb69d794f6b48cfa02b7bacd9559bded8e4fa67be7ed19a869501326560c79c35e9b90bebfaa4a18392192e299f61acedd2b328a37
         | 
    
        data/Gemfile
    CHANGED
    
    | @@ -2,7 +2,6 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            source "https://rubygems.org"
         | 
| 4 4 |  | 
| 5 | 
            -
            # Specify your gem's dependencies in active_record-associated_object.gemspec
         | 
| 6 5 | 
             
            gemspec
         | 
| 7 6 |  | 
| 8 7 | 
             
            gem "rake", "~> 13.0"
         | 
| @@ -14,6 +13,7 @@ gem "sqlite3" | |
| 14 13 | 
             
            # Integrations to setup and test with.
         | 
| 15 14 | 
             
            gem "kredis"
         | 
| 16 15 | 
             
            gem "activejob"
         | 
| 16 | 
            +
            gem "active_job-performs"
         | 
| 17 17 | 
             
            gem "railties"
         | 
| 18 18 |  | 
| 19 19 | 
             
            gem "minitest-sprint", "~> 1.2"
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                active_record-associated_object (0. | 
| 5 | 
            -
                  active_job-performs
         | 
| 4 | 
            +
                active_record-associated_object (0.5.1)
         | 
| 6 5 | 
             
                  activerecord (>= 6.1)
         | 
| 7 6 |  | 
| 8 7 | 
             
            GEM
         | 
| @@ -133,6 +132,7 @@ PLATFORMS | |
| 133 132 | 
             
              x86_64-linux
         | 
| 134 133 |  | 
| 135 134 | 
             
            DEPENDENCIES
         | 
| 135 | 
            +
              active_job-performs
         | 
| 136 136 | 
             
              active_record-associated_object!
         | 
| 137 137 | 
             
              activejob
         | 
| 138 138 | 
             
              debug
         | 
    
        data/README.md
    CHANGED
    
    | @@ -44,11 +44,47 @@ class Post::Publisher < ActiveRecord::AssociatedObject | |
| 44 44 | 
             
            end
         | 
| 45 45 | 
             
            ```
         | 
| 46 46 |  | 
| 47 | 
            -
            ###  | 
| 47 | 
            +
            ### Namespaced models
         | 
| 48 48 |  | 
| 49 | 
            -
             | 
| 49 | 
            +
            If you have a namespaced Active Record like this:
         | 
| 50 50 |  | 
| 51 | 
            -
             | 
| 51 | 
            +
            ```ruby
         | 
| 52 | 
            +
            # app/models/post/comment.rb
         | 
| 53 | 
            +
            class Post::Comment < ApplicationRecord
         | 
| 54 | 
            +
              belongs_to :post
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              has_object :rating
         | 
| 57 | 
            +
            end
         | 
| 58 | 
            +
            ```
         | 
| 59 | 
            +
             | 
| 60 | 
            +
            You can define the associated object in the same way it was done for `Post::Publisher` above, within the `Post::Comment` namespace:
         | 
| 61 | 
            +
             | 
| 62 | 
            +
            ```ruby
         | 
| 63 | 
            +
            # app/models/post/comment/rating.rb
         | 
| 64 | 
            +
            class Post::Comment::Rating < ActiveRecord::AssociatedObject
         | 
| 65 | 
            +
              def great?
         | 
| 66 | 
            +
                # A `comment` method is generated to access the associated comment. There's also a `record` alias available.
         | 
| 67 | 
            +
                comment.author.subscriber_of? comment.post.author
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
            end
         | 
| 70 | 
            +
            ```
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            ### Composite primary keys
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            We support Active Record models with composite primary keys out of the box.
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            Just setup the associated objects like the above examples and you've got GlobalID/Active Job and Kredis support automatically.
         | 
| 77 | 
            +
             | 
| 78 | 
            +
            ### Remove Active Job boilerplate with `performs`
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            If you also bundle [`active_job-performs`](https://github.com/kaspth/active_job-performs) in your Gemfile like this:
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            ```ruby
         | 
| 83 | 
            +
            gem "active_job-performs"
         | 
| 84 | 
            +
            gem "active_record-associated_object"
         | 
| 85 | 
            +
            ```
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            Every associated object now has access to the `performs` macro, so you can do this:
         | 
| 52 88 |  | 
| 53 89 | 
             
            ```ruby
         | 
| 54 90 | 
             
            class Post::Publisher < ActiveRecord::AssociatedObject
         | 
| @@ -64,7 +100,7 @@ class Post::Publisher < ActiveRecord::AssociatedObject | |
| 64 100 | 
             
            end
         | 
| 65 101 | 
             
            ```
         | 
| 66 102 |  | 
| 67 | 
            -
            is equivalent to:
         | 
| 103 | 
            +
            which is equivalent to this:
         | 
| 68 104 |  | 
| 69 105 | 
             
            ```ruby
         | 
| 70 106 | 
             
            class Post::Publisher < ActiveRecord::AssociatedObject
         | 
| @@ -97,6 +133,8 @@ class Post::Publisher < ActiveRecord::AssociatedObject | |
| 97 133 | 
             
            end
         | 
| 98 134 | 
             
            ```
         | 
| 99 135 |  | 
| 136 | 
            +
            See the `ActiveJob::Performs` README for more details.
         | 
| 137 | 
            +
             | 
| 100 138 | 
             
            ### Passing callbacks onto the associated object
         | 
| 101 139 |  | 
| 102 140 | 
             
            `has_object` accepts a hash of callbacks to pass.
         | 
| @@ -26,10 +26,5 @@ Gem::Specification.new do |spec| | |
| 26 26 | 
             
              end
         | 
| 27 27 | 
             
              spec.require_paths = ["lib"]
         | 
| 28 28 |  | 
| 29 | 
            -
              # Uncomment to register a new dependency of your gem
         | 
| 30 29 | 
             
              spec.add_dependency "activerecord", ">= 6.1"
         | 
| 31 | 
            -
              spec.add_dependency "active_job-performs"
         | 
| 32 | 
            -
             | 
| 33 | 
            -
              # For more information and examples about making a new gem, check out our
         | 
| 34 | 
            -
              # guide at: https://bundler.io/guides/creating_gem.html
         | 
| 35 30 | 
             
            end
         | 
| @@ -1,11 +1,15 @@ | |
| 1 1 | 
             
            class ActiveRecord::AssociatedObject::Railtie < Rails::Railtie
         | 
| 2 2 | 
             
              initializer "integrations.include" do
         | 
| 3 | 
            -
                 | 
| 4 | 
            -
             | 
| 3 | 
            +
                config.after_initialize do
         | 
| 4 | 
            +
                  ActiveRecord::AssociatedObject.include Kredis::Attributes       if defined?(Kredis)
         | 
| 5 | 
            +
                  ActiveRecord::AssociatedObject.include GlobalID::Identification if defined?(GlobalID)
         | 
| 5 6 |  | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 7 | 
            +
                  ActiveSupport.on_load :active_job do
         | 
| 8 | 
            +
                    require "active_job/performs"
         | 
| 9 | 
            +
                    ActiveRecord::AssociatedObject.extend ActiveJob::Performs
         | 
| 10 | 
            +
                  rescue LoadError
         | 
| 11 | 
            +
                    # We haven't bundled active_job-performs, so we're continuing without it.
         | 
| 12 | 
            +
                  end
         | 
| 9 13 | 
             
                end
         | 
| 10 14 | 
             
              end
         | 
| 11 15 |  | 
| @@ -2,17 +2,17 @@ class ActiveRecord::AssociatedObject | |
| 2 2 | 
             
              class << self
         | 
| 3 3 | 
             
                def inherited(klass)
         | 
| 4 4 | 
             
                  record_klass   = klass.module_parent
         | 
| 5 | 
            -
                  record_name    = klass.module_parent_name.underscore
         | 
| 5 | 
            +
                  record_name    = klass.module_parent_name.demodulize.underscore
         | 
| 6 6 | 
             
                  attribute_name = klass.to_s.demodulize.underscore.to_sym
         | 
| 7 7 |  | 
| 8 8 | 
             
                  unless record_klass.respond_to?(:descends_from_active_record?) && record_klass.descends_from_active_record?
         | 
| 9 9 | 
             
                    raise ArgumentError, "#{record_klass} isn't valid; can only associate with ActiveRecord::Base subclasses"
         | 
| 10 10 | 
             
                  end
         | 
| 11 11 |  | 
| 12 | 
            -
                  alias_method record_name, :record
         | 
| 13 | 
            -
                  define_singleton_method(:record_klass)   { record_klass }
         | 
| 14 | 
            -
                  define_singleton_method(:attribute_name) { attribute_name }
         | 
| 15 | 
            -
                  delegate :record_klass, :attribute_name, to: :class
         | 
| 12 | 
            +
                  klass.alias_method record_name, :record
         | 
| 13 | 
            +
                  klass.define_singleton_method(:record_klass)   { record_klass }
         | 
| 14 | 
            +
                  klass.define_singleton_method(:attribute_name) { attribute_name }
         | 
| 15 | 
            +
                  klass.delegate :record_klass, :attribute_name, to: :class
         | 
| 16 16 | 
             
                end
         | 
| 17 17 |  | 
| 18 18 | 
             
                def respond_to_missing?(...) = record_klass.respond_to?(...) || super
         | 
| @@ -39,4 +39,5 @@ class ActiveRecord::AssociatedObject | |
| 39 39 | 
             
              end
         | 
| 40 40 | 
             
            end
         | 
| 41 41 |  | 
| 42 | 
            +
            require_relative "associated_object/version"
         | 
| 42 43 | 
             
            require_relative "associated_object/railtie" if defined?(Rails::Railtie)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: active_record-associated_object
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.5.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Kasper Timm Hansen
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2023- | 
| 11 | 
            +
            date: 2023-11-05 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         | 
| @@ -24,20 +24,6 @@ dependencies: | |
| 24 24 | 
             
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '6.1'
         | 
| 27 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            -
              name: active_job-performs
         | 
| 29 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            -
                requirements:
         | 
| 31 | 
            -
                - - ">="
         | 
| 32 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: '0'
         | 
| 34 | 
            -
              type: :runtime
         | 
| 35 | 
            -
              prerelease: false
         | 
| 36 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            -
                requirements:
         | 
| 38 | 
            -
                - - ">="
         | 
| 39 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: '0'
         | 
| 41 27 | 
             
            description:
         | 
| 42 28 | 
             
            email:
         | 
| 43 29 | 
             
            - hey@kaspth.com
         |