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 +4 -4
- data/CHANGELOG.md +48 -0
- data/lib/ask/tokens/rails/configuration.rb +38 -0
- data/lib/ask/tokens/rails/models/token_transaction.rb +4 -1
- data/lib/ask/tokens/rails/models/token_wallet.rb +4 -1
- data/lib/ask/tokens/rails/version.rb +1 -1
- data/lib/ask-tokens-rails.rb +1 -0
- data/lib/generators/ask_tokens/install/install_generator.rb +1 -0
- data/lib/generators/ask_tokens/install/templates/migration.rb +8 -7
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fdcad46d2110412eb3a63e42de467fe7b2017dd0bcf84e821376889ce211fc2f
|
|
4
|
+
data.tar.gz: 5b2e076d4a745e5f142596c7176f5a7018d4d0a4992535bca90854dab00ee8fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
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,
|
data/lib/ask-tokens-rails.rb
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class CreateAskTokensTables < ActiveRecord::Migration[7.0]
|
|
4
4
|
def change
|
|
5
|
-
create_table
|
|
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
|
|
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
|
|
13
|
-
t.references :token_wallet, null: false, foreign_key:
|
|
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
|
|
23
|
-
add_index
|
|
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.
|
|
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.
|
|
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.
|
|
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
|