measured-rails 2.7.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +0 -3
- data/CHANGELOG.md +7 -0
- data/README.md +10 -0
- data/dev.yml +1 -1
- data/lib/measured/rails/active_record.rb +5 -1
- data/lib/measured/rails/version.rb +1 -1
- data/test/active_record_test.rb +20 -0
- data/test/support/models/thing_with_custom_value_accessor.rb +19 -0
- data/test/support/schema.rb +18 -1
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f53b4259959a215a55d423a3fb805982755d583a4d134ec2704df4017a58fc1
|
4
|
+
data.tar.gz: d28466e9df22e295aca2ed764411c8e55c0e7d2e63cda1d26d66a432ca789e5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17b097b9ed058aa86f20605b435bcb340a68a3fb9a7f40d5cb7fd4f17411634abf5d14f86057b735a84b4db20ac025bfb0809d7bec88e8636c9798e261dabba0
|
7
|
+
data.tar.gz: 2769862d7e7946e1a27f547fe7c0ef7ac4384a879619b63011376c57727337aa5ffbd790c99d3d20fe549885abb70edcfdd73cf5867ec1671c60a5c84255bdeb
|
data/.github/workflows/ci.yml
CHANGED
@@ -11,7 +11,6 @@ jobs:
|
|
11
11
|
fail-fast: false
|
12
12
|
matrix:
|
13
13
|
ruby:
|
14
|
-
- '2.5'
|
15
14
|
- '2.6'
|
16
15
|
- '2.7'
|
17
16
|
- '3.0'
|
@@ -22,8 +21,6 @@ jobs:
|
|
22
21
|
- gemfiles/rails-6.1.gemfile
|
23
22
|
- gemfiles/rails-edge.gemfile
|
24
23
|
exclude:
|
25
|
-
- ruby: '2.5'
|
26
|
-
gemfile: gemfiles/rails-edge.gemfile
|
27
24
|
- ruby: '2.6'
|
28
25
|
gemfile: gemfiles/rails-edge.gemfile
|
29
26
|
- ruby: '3.0'
|
data/CHANGELOG.md
CHANGED
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
@@ -25,7 +25,11 @@ module Measured::Rails::ActiveRecord
|
|
25
25
|
"#{ field }_unit"
|
26
26
|
end
|
27
27
|
|
28
|
-
value_field_name =
|
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
|
data/test/active_record_test.rb
CHANGED
@@ -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
|
data/test/support/schema.rb
CHANGED
@@ -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:
|
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.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin McPhillips
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-08 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.
|
19
|
+
version: 2.8.0
|
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.
|
26
|
+
version: 2.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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.
|
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
|