standard_procedure_fabrik 0.2.2 → 0.2.4
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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: cd5573ca4788578745a5a30a0bccaefda4dc491f8535ea52399e7b6ab595900d
         | 
| 4 | 
            +
              data.tar.gz: 4ff630d03615fc92cd670c40d903807587805ca1d865ae61a1279df664a62c25
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5dc48f0c99f743cdad6d48b1b18ea7ce162b1419b69e1966e66061d6a6ccc513333bdf655ef3dc6a9b3c15f06e2448c322abab5e44a615e4eb769a21e2fdc892
         | 
| 7 | 
            +
              data.tar.gz: db7c8a0bc3ef925b400a9ef00a0106dce6e0adc5082aed88a0b4fb8c1853873ece84711e4a7db6dc5a06c8eeccfb1e6c6def6c050a8b048ea57d8c8a00a14a69
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            2428a5a1e9e5cdde9e5f311be834934b1dec50614a9a1e4ccb2e805631184db0ca873699dbb5570e436abdffc8b485dd170a29acf3e7102f8189410ae731cb96
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            66c0bb9e19f7feffe5f6a96549979da37947f80058adbb6c57c4a1fef2f0ee1f16b272f05f52c79f60e015c6c1823cca1c3213fbf49534a7952af78a40b687ef
         | 
    
        data/lib/fabrik/database.rb
    CHANGED
    
    | @@ -11,14 +11,13 @@ module Fabrik | |
| 11 11 | 
             
                def register(klass, as: nil, &block)
         | 
| 12 12 | 
             
                  blueprint_name = (as.nil? ? blueprint_name_for(klass) : as.to_s.pluralize).to_sym
         | 
| 13 13 | 
             
                  blueprint = Blueprint.new(klass, &block)
         | 
| 14 | 
            -
                   | 
| 15 | 
            -
                  @blueprints[klass] = blueprint
         | 
| 14 | 
            +
                  set_blueprint_for(blueprint_name, blueprint)
         | 
| 16 15 |  | 
| 17 16 | 
             
                  define_singleton_method blueprint_name do
         | 
| 18 | 
            -
                    proxy_for | 
| 17 | 
            +
                    proxy_for blueprint_name
         | 
| 19 18 | 
             
                  end
         | 
| 20 19 |  | 
| 21 | 
            -
                  proxy_for | 
| 20 | 
            +
                  proxy_for blueprint_name
         | 
| 22 21 | 
             
                end
         | 
| 23 22 | 
             
                alias_method :with, :register
         | 
| 24 23 |  | 
| @@ -34,14 +33,21 @@ module Fabrik | |
| 34 33 |  | 
| 35 34 | 
             
                def initialize &config
         | 
| 36 35 | 
             
                  @blueprints = {}
         | 
| 37 | 
            -
                  @ | 
| 36 | 
            +
                  @proxies = {}
         | 
| 38 37 | 
             
                  instance_eval(&config) unless config.nil?
         | 
| 39 38 | 
             
                end
         | 
| 40 39 |  | 
| 41 40 | 
             
                private def blueprint_name_for(klass) = klass.name.split("::").map(&:underscore).join("_").pluralize
         | 
| 42 41 |  | 
| 43 | 
            -
                private def proxy_for( | 
| 44 | 
            -
                   | 
| 42 | 
            +
                private def proxy_for(klass_or_blueprint_name)
         | 
| 43 | 
            +
                  blueprint_name = klass_or_blueprint_name.is_a?(Class) ? blueprint_name_for(klass_or_blueprint_name) : klass_or_blueprint_name
         | 
| 44 | 
            +
                  @proxies[blueprint_name.to_sym] ||= Proxy.new(self, @blueprints[blueprint_name])
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                private def set_blueprint_for(name, blueprint)
         | 
| 48 | 
            +
                  @blueprints[name] = blueprint
         | 
| 49 | 
            +
                  @blueprints[blueprint.klass] = blueprint
         | 
| 50 | 
            +
                  proxy_for(name).blueprint = blueprint
         | 
| 45 51 | 
             
                end
         | 
| 46 52 |  | 
| 47 53 | 
             
                private def class_from(method_name)
         | 
| @@ -69,6 +75,8 @@ module Fabrik | |
| 69 75 |  | 
| 70 76 | 
             
                def respond_to_missing?(method_name, include_private = false) = @default_attributes.key?(method_name.to_sym) || super
         | 
| 71 77 |  | 
| 78 | 
            +
                def to_s = "#{klass} blueprint (#{object_id}) (#{default_attributes.keys.size} defaults, #{unique_keys.size} unique keys #{(!callback.nil?) ? "with callback" : ""})"
         | 
| 79 | 
            +
             | 
| 72 80 | 
             
                def initialize(klass, &block)
         | 
| 73 81 | 
             
                  @klass = klass
         | 
| 74 82 | 
             
                  @default_attributes = {}
         | 
| @@ -80,16 +88,22 @@ module Fabrik | |
| 80 88 | 
             
              class Proxy < SimpleDelegator
         | 
| 81 89 | 
             
                def create(label = nil, **attributes)
         | 
| 82 90 | 
             
                  (@blueprint.unique_keys.any? ? find_or_create_record(attributes) : create_record(attributes)).tap do |record|
         | 
| 83 | 
            -
                     | 
| 91 | 
            +
                    self[label] = record if label
         | 
| 84 92 | 
             
                  end
         | 
| 85 93 | 
             
                end
         | 
| 86 94 | 
             
                alias_method :create!, :create
         | 
| 87 95 |  | 
| 88 | 
            -
                def  | 
| 89 | 
            -
             | 
| 96 | 
            +
                def [](label) = @records[label.to_sym]
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                def []=(label, record)
         | 
| 99 | 
            +
                  @records[label.to_sym] = record
         | 
| 90 100 | 
             
                end
         | 
| 91 101 |  | 
| 92 | 
            -
                def  | 
| 102 | 
            +
                def method_missing(method_name, *args, &block) = self[method_name.to_sym] || super
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                def respond_to_missing?(method_name, include_private = false) = !self[method_name].nil? || super
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                def to_s = "Proxy #{object_id} for #{@blueprint} (#{@records.keys.size} records)"
         | 
| 93 107 |  | 
| 94 108 | 
             
                def initialize(db, blueprint)
         | 
| 95 109 | 
             
                  @db = db
         | 
| @@ -98,6 +112,8 @@ module Fabrik | |
| 98 112 | 
             
                  super(klass)
         | 
| 99 113 | 
             
                end
         | 
| 100 114 |  | 
| 115 | 
            +
                attr_accessor :blueprint
         | 
| 116 | 
            +
             | 
| 101 117 | 
             
                private def unique_keys = @blueprint.unique_keys
         | 
| 102 118 |  | 
| 103 119 | 
             
                private def klass = @blueprint.klass
         | 
    
        data/lib/fabrik/version.rb
    CHANGED
    
    
    
        data/lib/fabrik.rb
    CHANGED
    
    | @@ -4,10 +4,7 @@ require_relative "fabrik/version" | |
| 4 4 | 
             
            require_relative "fabrik/database"
         | 
| 5 5 |  | 
| 6 6 | 
             
            module Fabrik
         | 
| 7 | 
            -
              def self.configure(&block)
         | 
| 8 | 
            -
                @db ||= Database.new
         | 
| 9 | 
            -
                @db.configure(&block)
         | 
| 10 | 
            -
              end
         | 
| 7 | 
            +
              def self.configure(&block) = db.configure(&block)
         | 
| 11 8 |  | 
| 12 | 
            -
              def self.db = @db
         | 
| 9 | 
            +
              def self.db = @db ||= Database.new
         | 
| 13 10 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: standard_procedure_fabrik
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Rahoul Baruah
         | 
| 8 8 | 
             
            bindir: exe
         | 
| 9 9 | 
             
            cert_chain: []
         | 
| 10 | 
            -
            date: 2025-02- | 
| 10 | 
            +
            date: 2025-02-10 00:00:00.000000000 Z
         | 
| 11 11 | 
             
            dependencies:
         | 
| 12 12 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 13 13 | 
             
              name: activesupport
         | 
| @@ -58,6 +58,8 @@ files: | |
| 58 58 | 
             
            - checksums/standard_procedure_fabrik-0.2.0.gem.sha512
         | 
| 59 59 | 
             
            - checksums/standard_procedure_fabrik-0.2.1.gem.sha512
         | 
| 60 60 | 
             
            - checksums/standard_procedure_fabrik-0.2.2.gem.sha512
         | 
| 61 | 
            +
            - checksums/standard_procedure_fabrik-0.2.3.gem.sha512
         | 
| 62 | 
            +
            - checksums/standard_procedure_fabrik-0.2.4.gem.sha512
         | 
| 61 63 | 
             
            - lib/fabrik.rb
         | 
| 62 64 | 
             
            - lib/fabrik/database.rb
         | 
| 63 65 | 
             
            - lib/fabrik/version.rb
         |