whittaker_tech-midas 0.4.0 → 0.5.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: fe9c21222c40c9da18f01c21076e775b5d00f6f7b817f2c06c05223cdd88de8b
4
- data.tar.gz: 50ec83ec5d2b1fbe82e3856180ce63c8bc35f458679f14ab3fdd800229ef519d
3
+ metadata.gz: 0f638743662ef34c451ad0c93e3c00ccef2b1fb74c21520e5a6c0e98cf83b8a1
4
+ data.tar.gz: 2b44bc0773c678e7b9ecbdac928656cfc4e9a00c2c737fcfad0b08b892d71d8e
5
5
  SHA512:
6
- metadata.gz: 4833df22795e85d8e837bd2c0fa81ee6cf593a401463daf7ca42b6adf659be45cecd497213a0641d363c1523019fd2ac616265212aca85e531ee56d9d50efb7f
7
- data.tar.gz: bdcf127c769350759698cfefb12babe569c5c0c2ed907b3127212e2d806ff3c8eec0d9dedde9f62b6ec59721683e8fa99b21eeef883a6148166d567673dce20a
6
+ metadata.gz: e1ff7f68891ca65f9ca77aed3758c02f176bf6208fc11d3cc854d40d3b66f4a3f441cfe590d7b5794df773a575634f6fc3dabf5fb0e3e4beba0a8b3f14e9fd10
7
+ data.tar.gz: 15ebf018ffe904a87180df6cea837a92cdef2729596677047d81789ffdd1212fc098098d80bd85da38a095ef5ee0b1759892c79d5000ff29a31dd0b363a9240b
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![MIT License](https://img.shields.io/badge/license-MIT-green.svg)](MIT-LICENSE)
4
4
  ![Ruby 3.2](https://img.shields.io/badge/ruby-3.2+-red.svg)
5
- ![Rails 7.1](https://img.shields.io/badge/rails-7.1+-crimson.svg)
5
+ ![Rails 6.1](https://img.shields.io/badge/rails-6.1+-crimson.svg)
6
6
  [![Gem Version](https://badge.fury.io/rb/whittaker_tech-midas.svg)](https://badge.fury.io/rb/whittaker_tech-midas)
7
7
  [![CI](https://github.com/WhittakerTech/midas/actions/workflows/ci.yml/badge.svg)](https://github.com/WhittakerTech/midas/actions)
8
8
 
@@ -28,8 +28,11 @@ This design keeps your pricing, billing, and financial reporting consistent acro
28
28
 
29
29
  ## Requirements
30
30
 
31
- - Ruby 3.4+
32
- - Rails 7.1+
31
+ - Ruby 3.2+
32
+ - Rails 6.1+ (6.1 supported for legacy consumers, exercised in CI on Ruby 3.3;
33
+ `Ledger` uses the Rails 7.1 `enum` form where available and falls back to the
34
+ 6.1 syntax, where an unknown value raises `ArgumentError` on assignment rather
35
+ than becoming a validation error)
33
36
  - money gem ~> 6.19.0
34
37
 
35
38
  ## Installation
@@ -129,8 +129,8 @@ module WhittakerTech::Midas::Bankable
129
129
  def define_methods(name, label, assoc_name)
130
130
  define_method(name) { public_send(assoc_name) }
131
131
 
132
- define_method("#{name}_amount") { public_send(name)&.amount }
133
- define_method("#{name}_format") { public_send(name)&.amount&.format }
132
+ define_method("#{name}_amount") { public_send(name)&.amount }
133
+ define_method("#{name}_format") { public_send(name)&.amount&.format }
134
134
  define_method("#{name}_in") { |to| public_send(name)&.exchange_to(to)&.format }
135
135
 
136
136
  # Sets the coin value with the specified amount and currency.
@@ -26,14 +26,29 @@ class WhittakerTech::Midas::Ledger::Account < WhittakerTech::Midas::ApplicationR
26
26
  dependent: :restrict_with_error,
27
27
  inverse_of: :account
28
28
 
29
- enum :kind, {
29
+ KINDS = {
30
30
  asset: 'asset',
31
31
  liability: 'liability',
32
32
  equity: 'equity',
33
33
  revenue: 'revenue',
34
34
  expense: 'expense',
35
35
  suspense: 'suspense'
36
- }, validate: true
36
+ }.freeze
37
+
38
+ # Rails 7.1 introduced both the positional `enum :name, values` form and the
39
+ # `validate: true` option (unknown values become validation errors rather
40
+ # than raising ArgumentError on assignment). Rails 6.1 has neither, so the
41
+ # declaration is version-conditional. On 6.1 an unknown value still raises
42
+ # ArgumentError at assignment time -- stricter than 7.1+, never looser --
43
+ # and AR 6.1 offers no way to defer that to validation.
44
+ if ActiveRecord::VERSION::STRING >= '7.1'
45
+ enum :kind, KINDS, validate: true
46
+ else
47
+ # rubocop:disable Rails/EnumSyntax -- the positional form this cop wants
48
+ # is exactly what Rails 6.1 lacks; that is why this branch exists.
49
+ enum kind: KINDS
50
+ # rubocop:enable Rails/EnumSyntax
51
+ end
37
52
 
38
53
  before_validation :normalize_currency_code
39
54
 
@@ -31,7 +31,22 @@ class WhittakerTech::Midas::Ledger::Posting < WhittakerTech::Midas::ApplicationR
31
31
  # overriding so it can still be called.
32
32
  alias attach_amount_coin set_amount
33
33
 
34
- enum :direction, { debit: 'debit', credit: 'credit' }, validate: true
34
+ DIRECTIONS = { debit: 'debit', credit: 'credit' }.freeze
35
+
36
+ # Rails 7.1 introduced both the positional `enum :name, values` form and the
37
+ # `validate: true` option (unknown values become validation errors rather
38
+ # than raising ArgumentError on assignment). Rails 6.1 has neither, so the
39
+ # declaration is version-conditional. On 6.1 an unknown value still raises
40
+ # ArgumentError at assignment time -- stricter than 7.1+, never looser --
41
+ # and AR 6.1 offers no way to defer that to validation.
42
+ if ActiveRecord::VERSION::STRING >= '7.1'
43
+ enum :direction, DIRECTIONS, validate: true
44
+ else
45
+ # rubocop:disable Rails/EnumSyntax -- the positional form this cop wants
46
+ # is exactly what Rails 6.1 lacks; that is why this branch exists.
47
+ enum direction: DIRECTIONS
48
+ # rubocop:enable Rails/EnumSyntax
49
+ end
35
50
 
36
51
  validates :occurred_at, presence: true
37
52
  # account/entry are both present at creation time (before any amount is
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'whittaker_tech/midas'
4
4
 
5
- class CreateWhittakerTechSchema < ActiveRecord::Migration[8.0]
5
+ class CreateWhittakerTechSchema < ActiveRecord::Migration[6.1]
6
6
  SCHEMA_NAME = (WhittakerTech::Midas.table_namespace || 'midas').freeze
7
7
  raise 'Invalid schema name' unless SCHEMA_NAME =~ /\A[a-z_][a-z0-9_]*\z/
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'whittaker_tech/midas'
4
4
 
5
- class CreateMidasCoins < ActiveRecord::Migration[8.0]
5
+ class CreateMidasCoins < ActiveRecord::Migration[6.1]
6
6
  def change
7
7
  create_table WhittakerTech::Midas.table_name('coins') do |t|
8
8
  t.references :resource, polymorphic: true, null: false, index: true
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'whittaker_tech/midas'
4
4
 
5
- class RenameResourceLabelToResourceRoleInWtMidasCoins < ActiveRecord::Migration[8.0]
5
+ class RenameResourceLabelToResourceRoleInWtMidasCoins < ActiveRecord::Migration[6.1]
6
6
  def change
7
7
  rename_column WhittakerTech::Midas.table_name('coins'), :resource_label, :resource_role
8
8
  rename_index WhittakerTech::Midas.table_name('coins'),
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class RenameWtMidasCoinsToMidasCoins < ActiveRecord::Migration[8.0]
3
+ class RenameWtMidasCoinsToMidasCoins < ActiveRecord::Migration[6.1]
4
4
  def change
5
5
  rename_table :wt_midas_coins, :midas_coins
6
6
  rename_index :midas_coins,
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'whittaker_tech/midas'
4
4
 
5
- class CreateMidasExchanges < ActiveRecord::Migration[8.0]
5
+ class CreateMidasExchanges < ActiveRecord::Migration[6.1]
6
6
  def change
7
7
  create_table WhittakerTech::Midas.table_name('exchanges') do |t|
8
8
  t.decimal :rate, precision: 24, scale: 12, null: false
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'whittaker_tech/midas'
4
4
 
5
- class CreateMidasLedgerAccounts < ActiveRecord::Migration[8.0]
5
+ class CreateMidasLedgerAccounts < ActiveRecord::Migration[6.1]
6
6
  def change
7
7
  create_table WhittakerTech::Midas.table_name('ledger_accounts') do |t|
8
8
  t.references :owner, polymorphic: true, null: true, index: true
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'whittaker_tech/midas'
4
4
 
5
- class CreateMidasLedgerEntries < ActiveRecord::Migration[8.0]
5
+ class CreateMidasLedgerEntries < ActiveRecord::Migration[6.1]
6
6
  def change
7
7
  create_table WhittakerTech::Midas.table_name('ledger_entries') do |t|
8
8
  t.string :currency_code, null: false, limit: 3
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'whittaker_tech/midas'
4
4
 
5
- class CreateMidasLedgerPostings < ActiveRecord::Migration[8.0]
5
+ class CreateMidasLedgerPostings < ActiveRecord::Migration[6.1]
6
6
  def change
7
7
  create_table WhittakerTech::Midas.table_name('ledger_postings') do |t|
8
8
  t.references(
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class WhittakerTech::Midas::Generators::InstallGenerator < Rails::Generators::Base
3
+ class WhittakerTech::Midas::InstallGenerator < Rails::Generators::Base
4
4
  desc 'Installs Midas and copies migrations.'
5
5
 
6
6
  def copy_migrations
@@ -108,6 +108,15 @@ class WhittakerTech::Midas::Engine < Rails::Engine
108
108
  config.eager_load_paths += Dir["#{config.root}/app/models"]
109
109
 
110
110
  initializer 'midas.helpers' do
111
+ # Explicit require rather than relying on Zeitwerk autoload resolution
112
+ # here: ActiveSupport.on_load(:action_view) fires immediately (not
113
+ # deferred) whenever ActionView::Base is already loaded by the time this
114
+ # initializer runs, which on Rails 8 hosts happens before this engine's
115
+ # own autoload paths are guaranteed ready -- raising a NameError on boot
116
+ # for WhittakerTech::Midas::FormHelper. Requiring the file directly
117
+ # sidesteps the race entirely.
118
+ require_relative '../../../app/helpers/whittaker_tech/midas/form_helper'
119
+
111
120
  ActiveSupport.on_load(:action_view) do
112
121
  include WhittakerTech::Midas::FormHelper
113
122
  end
@@ -1,5 +1,10 @@
1
+ # rubocop:disable Style/OneClassPerFile -- .rubocop.yml enforces compact
2
+ # module style (Style/ClassAndModuleChildren: compact), which requires the
3
+ # parent module to be opened separately. The two cops are mutually exclusive
4
+ # here; compact style wins because it is the repo-wide convention.
1
5
  module WhittakerTech; end
2
6
 
3
7
  module WhittakerTech::Midas
4
- VERSION = '0.4.0'.freeze
8
+ VERSION = '0.5.0'.freeze
5
9
  end
10
+ # rubocop:enable Style/OneClassPerFile
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whittaker_tech-midas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Whittaker
@@ -29,28 +29,28 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '1.0'
32
+ version: '1.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '1.0'
39
+ version: '1.3'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rails
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 7.1.5.2
46
+ version: '6.1'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 7.1.5.2
53
+ version: '6.1'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: factory_bot_rails
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -97,16 +97,16 @@ dependencies:
97
97
  name: rspec-rails
98
98
  requirement: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: '7.0'
102
+ version: '6.1'
103
103
  type: :development
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '7.0'
109
+ version: '6.1'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: shoulda-matchers
112
112
  requirement: !ruby/object:Gem::Requirement