measured-rails 2.6.0 → 2.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd5658fda3d706ca2a15122793008dea4a312e8fe6dccbeb72743dbabc165d1d
4
- data.tar.gz: 96eb251668aca9622ec35cafba76730edfa1243749b8cdced184aa6e49c2c754
3
+ metadata.gz: dd3b14a42a96727f80163ed52e53634447e42c65b21ce3456005a37816d4f102
4
+ data.tar.gz: 375fa0c585f3bef90e286640b0a1e5c1b3e7ddee654eed3d1b22f3bd8f40c2d7
5
5
  SHA512:
6
- metadata.gz: 130a3980eb4b1eaa5de174316ac1073f144bb1bf9676a906f68f3cc44bb3752a825b81a5a5cc20768c01ad86cad5ee0cb7ca24e32a28327bd0f6853b564fb4bb
7
- data.tar.gz: edcb3fd7eb2fdd691c49cd31f44047d0cf1d63c3ebe5e27fbad3bd96aee8a2ed965c48ac29da846d11c0ca3f2ac592698e26b6ca9faeff2ea9f5dfe55475a5c8
6
+ metadata.gz: ab7fedf62f1aa93ecee4a9fdb6d32c245cd91a480d132ff524f5a54dee506006be80c10a0865649d5fa6cc350003dbba360905726cc0417c0849a6c3ca0a4cf5
7
+ data.tar.gz: 56d47429dc8d6c126c28a4e0e5ff3a9b3d98982096a8768dad60e68e1f5f3b5144a4f7f76c3c50d91800b385fb80b79e89fbcf2c59a7ceef91f586bc9638f5ef
@@ -8,17 +8,23 @@ jobs:
8
8
  env:
9
9
  BUNDLE_GEMFILE: ${{ matrix.gemfile }}
10
10
  strategy:
11
+ fail-fast: false
11
12
  matrix:
12
13
  ruby:
13
- - 2.5
14
- - 2.6
15
- - 2.7
14
+ - '2.6'
15
+ - '2.7'
16
+ - '3.0'
16
17
  gemfile:
17
18
  - Gemfile
18
19
  - gemfiles/rails-5.2.gemfile
19
20
  - gemfiles/rails-6.0.gemfile
20
21
  - gemfiles/rails-6.1.gemfile
21
- - gemfiles/rails-master.gemfile
22
+ - gemfiles/rails-edge.gemfile
23
+ exclude:
24
+ - ruby: '2.6'
25
+ gemfile: gemfiles/rails-edge.gemfile
26
+ - ruby: '3.0'
27
+ gemfile: gemfiles/rails-5.2.gemfile
22
28
  name: Ruby ${{ matrix.ruby }} ${{ matrix.gemfile }}
23
29
  steps:
24
30
  - uses: actions/checkout@v1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ Unreleased
2
+ -----
3
+
4
+
5
+
6
+ 2.8.2
7
+ -----
8
+
9
+ * Bump measured to 2.8.2
10
+
11
+ 2.8.1
12
+ -----
13
+
14
+ * Bump measured to 2.8.1
15
+
16
+ 2.8.0
17
+ -----
18
+
19
+ * Support setting a custom value field. (Thanks @Steffylicious)
20
+ * Drop support for Ruby 2.5
21
+ * Use Ruby 3.0.2 for development
22
+
23
+ 2.7.1
24
+ -----
25
+
26
+ * Bump measured to 2.7.1
27
+
1
28
  2.6.0
2
29
  -----
3
30
 
data/README.md CHANGED
@@ -54,6 +54,16 @@ class ThingWithCustomUnitAccessor < ActiveRecord::Base
54
54
  end
55
55
  ```
56
56
 
57
+ Similarly, you can optionally customize the model's value column by specifying it in the `value_field_name` option, as follows:
58
+
59
+ ```ruby
60
+ class ThingWithCustomValueAccessor < ActiveRecord::Base
61
+ measured_length :length, value_field_name: :custom_length
62
+ measured_weight :total_weight, value_field_name: :custom_weight
63
+ measured_volume :volume, value_field_name: :custom_volume
64
+ end
65
+ ```
66
+
57
67
  There are some simpler methods for predefined types:
58
68
 
59
69
  ```ruby
data/dev.yml CHANGED
@@ -2,7 +2,7 @@ name: measured-rails
2
2
 
3
3
  up:
4
4
  - ruby:
5
- version: 2.6.3
5
+ version: 3.0.2
6
6
  - bundler
7
7
 
8
8
  commands:
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'rails', github: 'rails/rails'
5
+ gem 'rails', github: 'rails/rails', branch: 'main'
@@ -25,7 +25,11 @@ module Measured::Rails::ActiveRecord
25
25
  "#{ field }_unit"
26
26
  end
27
27
 
28
- value_field_name = "#{ field }_value"
28
+ value_field_name = if options[:value_field_name]
29
+ measured_fields[field][:value_field_name] = options[:value_field_name].to_s
30
+ else
31
+ "#{ field }_value"
32
+ end
29
33
 
30
34
  # Reader to retrieve measured object
31
35
  define_method(field) do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Measured
3
3
  module Rails
4
- VERSION = "2.6.0"
4
+ VERSION = "2.8.2"
5
5
  end
6
6
  end
@@ -364,6 +364,15 @@ class Measured::Rails::ActiveRecordTest < ActiveSupport::TestCase
364
364
  assert_equal custom_unit_thing.extra_weight, Measured::Weight.new(12, :kg)
365
365
  end
366
366
 
367
+ test "using custom value fields works correctly" do
368
+ assert_equal custom_value_thing.length, Measured::Length.new(4, :m)
369
+ assert_equal custom_value_thing.width, Measured::Length.new(5, :m)
370
+ assert_equal custom_value_thing.height, Measured::Length.new(6, :m)
371
+ assert_equal custom_value_thing.volume, Measured::Volume.new(13, :l)
372
+ assert_equal custom_value_thing.total_weight, Measured::Weight.new(14, :g)
373
+ assert_equal custom_value_thing.extra_weight, Measured::Weight.new(15, :g)
374
+ end
375
+
367
376
  private
368
377
 
369
378
  def length
@@ -410,4 +419,15 @@ class Measured::Rails::ActiveRecordTest < ActiveSupport::TestCase
410
419
  extra_weight: Measured::Weight.new(12, :g),
411
420
  )
412
421
  end
422
+
423
+ def custom_value_thing
424
+ @custom_value_thing ||= ThingWithCustomValueAccessor.new(
425
+ length: Measured::Length.new(4, :m),
426
+ width: Measured::Length.new(5, :m),
427
+ height: Measured::Length.new(6, :m),
428
+ volume: Measured::Volume.new(13, :l),
429
+ total_weight: Measured::Weight.new(14, :g),
430
+ extra_weight: Measured::Weight.new(15, :g),
431
+ )
432
+ end
413
433
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ class ThingWithCustomValueAccessor < ActiveRecord::Base
3
+ measured_length :length, value_field_name: :custom_length
4
+ validates :length, measured: true
5
+ measured_length :width, value_field_name: :custom_width
6
+ validates :width, measured: true
7
+
8
+ measured_volume :volume, value_field_name: :custom_volume
9
+ validates :volume, measured: true
10
+
11
+ measured_length :height, value_field_name: :custom_height
12
+ validates :height, measured: true
13
+
14
+ measured_weight :total_weight, value_field_name: :custom_weight
15
+ validates :total_weight, measured: true
16
+
17
+ measured_weight :extra_weight, value_field_name: :custom_extra_weight
18
+ validates :extra_weight, measured: true
19
+ end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 20161118203701) do
13
+ ActiveRecord::Schema.define(version: 20211105120355) do
14
14
 
15
15
  create_table "thing_with_custom_unit_accessors", force: :cascade do |t|
16
16
  t.decimal "length_value", precision: 10, scale: 2
@@ -80,4 +80,21 @@ ActiveRecord::Schema.define(version: 20161118203701) do
80
80
  t.string "length_numericality_less_than_than_scalar_unit", limit: 12
81
81
  end
82
82
 
83
+ create_table "thing_with_custom_value_accessors", force: :cascade do |t|
84
+ t.decimal "custom_length", precision: 10, scale: 2
85
+ t.string "length_unit", limit: 12
86
+ t.decimal "custom_width", precision: 10, scale: 2
87
+ t.string "width_unit", limit: 12
88
+ t.decimal "custom_height", precision: 10, scale: 2
89
+ t.string "height_unit", limit: 12
90
+ t.decimal "custom_volume", precision: 10, scale: 2
91
+ t.string "volume_unit", limit: 12
92
+ t.decimal "custom_weight", precision: 10, scale: 2, default: "10.0"
93
+ t.string "total_weight_unit", limit: 12
94
+ t.decimal "custom_extra_weight", precision: 10, scale: 2
95
+ t.string "extra_weight_unit", limit: 12
96
+ t.datetime "created_at", null: false
97
+ t.datetime "updated_at", null: false
98
+ end
99
+
83
100
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measured-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McPhillips
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: measured
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.6.0
19
+ version: 2.8.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.6.0
26
+ version: 2.8.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: railties
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -169,7 +169,7 @@ files:
169
169
  - gemfiles/rails-5.2.gemfile
170
170
  - gemfiles/rails-6.0.gemfile
171
171
  - gemfiles/rails-6.1.gemfile
172
- - gemfiles/rails-master.gemfile
172
+ - gemfiles/rails-edge.gemfile
173
173
  - lib/measured-rails.rb
174
174
  - lib/measured/rails/active_record.rb
175
175
  - lib/measured/rails/base.rb
@@ -184,6 +184,7 @@ files:
184
184
  - test/active_record_test.rb
185
185
  - test/support/models/thing.rb
186
186
  - test/support/models/thing_with_custom_unit_accessor.rb
187
+ - test/support/models/thing_with_custom_value_accessor.rb
187
188
  - test/support/models/validated_thing.rb
188
189
  - test/support/schema.rb
189
190
  - test/test_helper.rb
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
209
  - !ruby/object:Gem::Version
209
210
  version: '0'
210
211
  requirements: []
211
- rubygems_version: 3.0.3
212
+ rubygems_version: 3.2.20
212
213
  signing_key:
213
214
  specification_version: 4
214
215
  summary: Rails adaptor for measured
@@ -216,6 +217,7 @@ test_files:
216
217
  - test/active_record_test.rb
217
218
  - test/support/models/thing.rb
218
219
  - test/support/models/thing_with_custom_unit_accessor.rb
220
+ - test/support/models/thing_with_custom_value_accessor.rb
219
221
  - test/support/models/validated_thing.rb
220
222
  - test/support/schema.rb
221
223
  - test/test_helper.rb