dddr 2.4.0 → 2.6.0
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/lib/dddr/sequel.rb +31 -65
- data/lib/dddr/version.rb +1 -1
- data/lib/dddr.rb +14 -0
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d6acdebe892f8a4b6cdf9ca92fda7bf75ed5b9070cef4ab7026c5422e8afd3ff
         | 
| 4 | 
            +
              data.tar.gz: 3139cede6e45ca82aece8f39bd85683b87f6892aa4a58592878f348ab4e47d3b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 6fea9815112baa6abd60096e2de8da23f509711fef58792bb87dbc4a776ff5057d43d549260c85937ddbfd6a4ae6eff3c47053f6220e8d7dac7de500708e4224
         | 
| 7 | 
            +
              data.tar.gz: d2bb17024d3c636b0687817b270f18020359abcbea4ad9f937756f6bd04f8b43eaf377d193ed8537d6fb2e33729377c579e68ef0df9b0f4fdff0e295f14d9757
         | 
    
        data/lib/dddr/sequel.rb
    CHANGED
    
    | @@ -1,15 +1,13 @@ | |
| 1 1 | 
             
            require "sequel"
         | 
| 2 | 
            +
            require "securerandom"
         | 
| 2 3 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 4 | 
            +
            # Assuming Dddr.configuration.db is already set up to return a Sequel database connection
         | 
| 5 5 | 
             
            module Dddr
         | 
| 6 6 | 
             
              module Sequel
         | 
| 7 7 | 
             
                module ClassMethods
         | 
| 8 8 | 
             
                  def create_properties(*names)
         | 
| 9 | 
            -
                    names.each do |name|
         | 
| 10 | 
            -
                       | 
| 11 | 
            -
                        attr_accessor name
         | 
| 12 | 
            -
                      end
         | 
| 9 | 
            +
                    names.flatten.each do |name|
         | 
| 10 | 
            +
                      attr_accessor name
         | 
| 13 11 | 
             
                    end
         | 
| 14 12 | 
             
                  end
         | 
| 15 13 |  | 
| @@ -20,8 +18,8 @@ module Dddr | |
| 20 18 | 
             
                  end
         | 
| 21 19 |  | 
| 22 20 | 
             
                  def table(name = nil)
         | 
| 23 | 
            -
                     | 
| 24 | 
            -
                     | 
| 21 | 
            +
                    @table_name = name unless name.nil?
         | 
| 22 | 
            +
                    @table_name
         | 
| 25 23 | 
             
                  end
         | 
| 26 24 |  | 
| 27 25 | 
             
                  def queries(&block)
         | 
| @@ -41,13 +39,12 @@ module Dddr | |
| 41 39 |  | 
| 42 40 | 
             
                  def create_repository_for(entity_class)
         | 
| 43 41 | 
             
                    repository_class = Class.new(RepositoryBase) do
         | 
| 44 | 
            -
                      define_singleton_method(: | 
| 45 | 
            -
                         | 
| 42 | 
            +
                      define_singleton_method(:entity_class) do
         | 
| 43 | 
            +
                        entity_class
         | 
| 46 44 | 
             
                      end
         | 
| 47 45 | 
             
                    end
         | 
| 48 46 |  | 
| 49 47 | 
             
                    repository_class.include(@queries_module) if instance_variable_defined?(:@queries_module)
         | 
| 50 | 
            -
             | 
| 51 48 | 
             
                    const_set(:Repository, repository_class)
         | 
| 52 49 | 
             
                  end
         | 
| 53 50 | 
             
                end
         | 
| @@ -55,81 +52,50 @@ module Dddr | |
| 55 52 | 
             
                class RepositoryBase
         | 
| 56 53 | 
             
                  attr_reader :dataset
         | 
| 57 54 |  | 
| 58 | 
            -
                  def initialize | 
| 59 | 
            -
                    @ | 
| 60 | 
            -
                     | 
| 61 | 
            -
                    @entity_class.create_properties(@dataset.columns)
         | 
| 55 | 
            +
                  def initialize
         | 
| 56 | 
            +
                    @dataset = Dddr.configuration.db[self.class.entity_class.table]
         | 
| 57 | 
            +
                    self.class.entity_class.create_properties(@dataset.columns)
         | 
| 62 58 | 
             
                  end
         | 
| 63 59 |  | 
| 64 60 | 
             
                  def count
         | 
| 65 61 | 
             
                    @dataset.count
         | 
| 66 62 | 
             
                  end
         | 
| 67 63 |  | 
| 68 | 
            -
                  def  | 
| 69 | 
            -
                     | 
| 70 | 
            -
                     | 
| 71 | 
            -
                    @dataset.insert(entity.to_hash)
         | 
| 72 | 
            -
                    uid
         | 
| 64 | 
            +
                  def get(uid)
         | 
| 65 | 
            +
                    row = @dataset.where(uid: uid).first
         | 
| 66 | 
            +
                    self.class.entity_class.from_row(row) if row
         | 
| 73 67 | 
             
                  end
         | 
| 74 | 
            -
                  alias_method :create, :add
         | 
| 75 | 
            -
                  alias_method :insert, :add
         | 
| 76 68 |  | 
| 77 69 | 
             
                  def update(entity)
         | 
| 70 | 
            +
                    entity.last_updated_at = DateTime.now
         | 
| 78 71 | 
             
                    @dataset.where(uid: entity.uid).update(entity.to_hash)
         | 
| 79 72 | 
             
                  end
         | 
| 80 73 |  | 
| 81 | 
            -
                   | 
| 82 | 
            -
             | 
| 83 | 
            -
                   | 
| 84 | 
            -
                  alias_method :revise, :update
         | 
| 85 | 
            -
                  alias_method :alter, :update
         | 
| 74 | 
            +
                  def all
         | 
| 75 | 
            +
                    @dataset.map { |row| self.class.entity_class.from_row(row) }
         | 
| 76 | 
            +
                  end
         | 
| 86 77 |  | 
| 87 78 | 
             
                  def delete(entity)
         | 
| 88 79 | 
             
                    @dataset.where(uid: entity.uid).delete
         | 
| 89 80 | 
             
                  end
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                  alias_method :remove, :delete
         | 
| 92 | 
            -
                  alias_method :erase, :delete
         | 
| 93 | 
            -
                  alias_method :discard, :delete
         | 
| 94 | 
            -
                  alias_method :destroy, :delete
         | 
| 95 | 
            -
                  alias_method :wipe, :delete
         | 
| 96 | 
            -
             | 
| 97 | 
            -
                  def get(uid)
         | 
| 98 | 
            -
                    row = @dataset.where(uid: uid).first
         | 
| 99 | 
            -
                    raise Dddr::Error, "UID is required" unless row
         | 
| 100 | 
            -
                    item = Item.new
         | 
| 101 | 
            -
                    item.from_hash(uid, row)
         | 
| 102 | 
            -
                    item
         | 
| 103 | 
            -
                  end
         | 
| 104 | 
            -
             | 
| 81 | 
            +
                  
         | 
| 105 82 | 
             
                  alias_method :find, :get
         | 
| 106 83 |  | 
| 107 | 
            -
                  def  | 
| 108 | 
            -
                     | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
                    end
         | 
| 113 | 
            -
                  end
         | 
| 114 | 
            -
                end
         | 
| 84 | 
            +
                  def add(entity)
         | 
| 85 | 
            +
                    uid = SecureRandom.uuid
         | 
| 86 | 
            +
                    entity.uid = uid
         | 
| 87 | 
            +
                    entity.created_at ||= DateTime.now.to_s
         | 
| 88 | 
            +
                    entity.last_updated_at ||= entity.created_at
         | 
| 115 89 |  | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
                  instance_variables.each do |var_name|
         | 
| 119 | 
            -
                    attribute_name = var_name.to_s[1..].to_sym
         | 
| 120 | 
            -
                    result[attribute_name] = instance_variable_get(var_name)
         | 
| 90 | 
            +
                    @dataset.insert(entity.to_hash)
         | 
| 91 | 
            +
                    uid
         | 
| 121 92 | 
             
                  end
         | 
| 122 | 
            -
                   | 
| 123 | 
            -
             | 
| 93 | 
            +
                  alias_method :create, :add
         | 
| 94 | 
            +
                  alias_method :insert, :add
         | 
| 124 95 |  | 
| 125 | 
            -
             | 
| 126 | 
            -
                  self.uid = uid
         | 
| 127 | 
            -
                  data_hash.each do |attribute, value|
         | 
| 128 | 
            -
                    attribute = attribute.to_sym
         | 
| 129 | 
            -
                    if respond_to?(:"#{attribute}=")
         | 
| 130 | 
            -
                      send(:"#{attribute}=", value)
         | 
| 131 | 
            -
                    end
         | 
| 132 | 
            -
                  end
         | 
| 96 | 
            +
                  # Methods update, delete, get, etc., remain unchanged.
         | 
| 133 97 | 
             
                end
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                
         | 
| 134 100 | 
             
              end
         | 
| 135 101 | 
             
            end
         | 
    
        data/lib/dddr/version.rb
    CHANGED
    
    
    
        data/lib/dddr.rb
    CHANGED
    
    | @@ -75,6 +75,20 @@ module Dddr | |
| 75 75 | 
             
                  end
         | 
| 76 76 |  | 
| 77 77 | 
             
                end
         | 
| 78 | 
            +
                
         | 
| 79 | 
            +
                def to_hash
         | 
| 80 | 
            +
                  instance_variables.each_with_object({}) do |var, hash|
         | 
| 81 | 
            +
                    hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
         | 
| 82 | 
            +
                  end
         | 
| 83 | 
            +
                end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                def from_hash(uid, data_hash)
         | 
| 86 | 
            +
                  self.uid = uid
         | 
| 87 | 
            +
                  data_hash.each do |attribute, value|
         | 
| 88 | 
            +
                    send(:"#{attribute}=", value) if respond_to?(:"#{attribute}=")
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
                end
         | 
| 91 | 
            +
             | 
| 78 92 |  | 
| 79 93 | 
             
                attr_accessor :uid, :created_at, :last_updated_at, :deleted, :deleted_at
         | 
| 80 94 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dddr
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2. | 
| 4 | 
            +
              version: 2.6.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Delaney Burke
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-03- | 
| 11 | 
            +
            date: 2024-03-23 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: sdbm
         |