ask-tokens-rails 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f36ea3ade0e11cbb7a52d00ae56f1168574ce7a559ce8995cc6ca43d6716de8
4
- data.tar.gz: c5b9d81ebc12fe4a51080cd773d8728dad5eb75ffbd50f15329623083ba8dcf9
3
+ metadata.gz: fdcad46d2110412eb3a63e42de467fe7b2017dd0bcf84e821376889ce211fc2f
4
+ data.tar.gz: 5b2e076d4a745e5f142596c7176f5a7018d4d0a4992535bca90854dab00ee8fd
5
5
  SHA512:
6
- metadata.gz: 48e3aaefc5ac428854b2c998fe9f4c66f9bd0b78483184ef17ac43494ddd52c77f0dc2939c4bdab114f14222bc208a5174536212c027b90417d3d77f8373e3a4
7
- data.tar.gz: 29dff0d60146f50f546f20be6643e8c8bd938c671a9d74f238c84f030af048ca07558fd5154e63d44641111352496382f7db00ea379554d29ecf5e1baafb8bb5
6
+ metadata.gz: 766ea99978a9c0349aa14d1a43862207524c1d3e1283aaad37bc5763b675513949b0944d3ba477a84b07ff72cedd28a3cb231a9856e6cf0671203527e586806b
7
+ data.tar.gz: fc318decca8131817e478b3f6ff0f7773d7c7e6bb6ad08f2ac3f356da265a671f12d090c3d646a68795f9afb7fa7cfb73136d033dcf92ca6be3096edb3985545
data/CHANGELOG.md CHANGED
@@ -1,3 +1,51 @@
1
+ ## [0.3.0] — 2026-09-14
2
+
3
+ ### Changed
4
+
5
+
6
+
7
+ - **Default table names are now gem-prefixed: `ask_tokens_wallets` and
8
+
9
+ `ask_tokens_transactions`.** They can no longer collide with an app's own
10
+
11
+ ledger, so no app configuration is needed. To keep the old names (or adopt
12
+
13
+ existing tables), configure them:
14
+
15
+
16
+
17
+ ```ruby
18
+
19
+ Ask::Tokens::Rails.configure do |config|
20
+
21
+ config.wallets_table = "token_wallets"
22
+
23
+ config.transactions_table = "token_transactions"
24
+
25
+ end
26
+
27
+ ```
28
+
29
+
30
+
31
+ Existing installs must either set the configuration above or rename their
32
+
33
+ tables in a migration.
34
+
35
+
36
+
37
+ ### Added
38
+
39
+
40
+
41
+ - `Ask::Tokens::Rails.configure` and `reset_config!` — configurable wallet
42
+
43
+ and transaction table names, honoured by the models and the install
44
+
45
+ generator.
46
+
47
+
48
+
1
49
  # Changelog
2
50
 
3
51
  ## [0.1.0] - 2026-08-19
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ask
4
+ module Tokens
5
+ module Rails
6
+ # Table names are prefixed with the gem's name by default, so they can
7
+ # never collide with an app's own ledger — no configuration needed.
8
+ # Override only to adopt existing tables:
9
+ #
10
+ # Ask::Tokens::Rails.configure do |config|
11
+ # config.wallets_table = "token_wallets"
12
+ # config.transactions_table = "token_transactions"
13
+ # end
14
+ class Configuration
15
+ attr_accessor :wallets_table, :transactions_table
16
+
17
+ def initialize
18
+ @wallets_table = "ask_tokens_wallets"
19
+ @transactions_table = "ask_tokens_transactions"
20
+ end
21
+ end
22
+
23
+ class << self
24
+ def config
25
+ @config ||= Configuration.new
26
+ end
27
+
28
+ def configure
29
+ yield config
30
+ end
31
+
32
+ def reset_config!
33
+ @config = Configuration.new
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -1,13 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_record"
4
+ require_relative "../configuration"
4
5
 
5
6
  module Ask
6
7
  module Tokens
7
8
  # Append-only ledger row. Every grant, debit, adjustment, or expiry is
8
9
  # written here as an immutable record. Never updated or deleted.
9
10
  class TokenTransaction < ::ActiveRecord::Base
10
- self.table_name = "token_transactions"
11
+ def self.table_name
12
+ Ask::Tokens::Rails.config.transactions_table
13
+ end
11
14
 
12
15
  belongs_to :token_wallet, class_name: "Ask::Tokens::TokenWallet",
13
16
  foreign_key: :token_wallet_id,
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "active_record"
4
+ require_relative "../configuration"
4
5
 
5
6
  module Ask
6
7
  module Tokens
7
8
  # Polymorphic wallet record. One per owner. Holds the cached balance.
8
9
  class TokenWallet < ::ActiveRecord::Base
9
- self.table_name = "token_wallets"
10
+ def self.table_name
11
+ Ask::Tokens::Rails.config.wallets_table
12
+ end
10
13
 
11
14
  has_many :token_transactions, class_name: "Ask::Tokens::TokenTransaction",
12
15
  foreign_key: :token_wallet_id,
@@ -3,7 +3,7 @@
3
3
  module Ask
4
4
  module Tokens
5
5
  module Rails
6
- VERSION = "0.2.1"
6
+ VERSION = "0.3.0"
7
7
  end
8
8
  end
9
9
  end
@@ -2,4 +2,5 @@
2
2
 
3
3
  require "ask-tokens"
4
4
  require "ask/tokens/rails/version"
5
+ require "ask/tokens/rails/configuration"
5
6
  require "ask/tokens/rails/railtie"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ask-tokens-rails"
3
4
  require "rails/generators"
4
5
  require "rails/generators/migration"
5
6
 
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class CreateTokenWallets < ActiveRecord::Migration[7.0]
3
+ class CreateAskTokensTables < ActiveRecord::Migration[7.0]
4
4
  def change
5
- create_table :token_wallets do |t|
5
+ create_table :<%= Ask::Tokens::Rails.config.wallets_table %> do |t|
6
6
  t.references :owner, polymorphic: true, null: false
7
7
  t.bigint :balance, null: false, default: 0
8
8
  t.timestamps
9
9
  end
10
- add_index :token_wallets, %i[owner_type owner_id], unique: true, name: "idx_token_wallets_owner"
10
+ add_index :<%= Ask::Tokens::Rails.config.wallets_table %>, %i[owner_type owner_id], unique: true,
11
+ name: "idx_<%= Ask::Tokens::Rails.config.wallets_table %>_owner"
11
12
 
12
- create_table :token_transactions do |t|
13
- t.references :token_wallet, null: false, foreign_key: true
13
+ create_table :<%= Ask::Tokens::Rails.config.transactions_table %> do |t|
14
+ t.references :token_wallet, null: false, foreign_key: {to_table: Ask::Tokens::Rails.config.wallets_table}
14
15
  t.string :entry_type, null: false
15
16
  t.bigint :amount, null: false
16
17
  t.string :reason, null: false
@@ -19,7 +20,7 @@ class CreateTokenWallets < ActiveRecord::Migration[7.0]
19
20
  t.datetime :expires_at
20
21
  t.datetime :created_at, null: false
21
22
  end
22
- add_index :token_transactions, %i[token_wallet_id created_at]
23
- add_index :token_transactions, :entry_type
23
+ add_index :<%= Ask::Tokens::Rails.config.transactions_table %>, %i[token_wallet_id created_at]
24
+ add_index :<%= Ask::Tokens::Rails.config.transactions_table %>, :entry_type
24
25
  end
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-tokens-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.2.0
18
+ version: 0.2.1
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.2.0
25
+ version: 0.2.1
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rails
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +93,7 @@ files:
93
93
  - README.md
94
94
  - lib/ask-tokens-rails.rb
95
95
  - lib/ask/tokens/rails/concerns/has_token_wallet.rb
96
+ - lib/ask/tokens/rails/configuration.rb
96
97
  - lib/ask/tokens/rails/jobs/sweep_expired_tokens_job.rb
97
98
  - lib/ask/tokens/rails/models/token_transaction.rb
98
99
  - lib/ask/tokens/rails/models/token_wallet.rb