unit_measurements-rails 1.5.0 → 1.6.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 +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +27 -16
- data/lib/unit_measurements/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02e353f4bcd5f1cad16b7bebee4a1d46dc226ece9768ffc6f08a05bc62448cab
|
4
|
+
data.tar.gz: f2d6ab2245a058aef8552669085b3086c682653cb1647f799af3a98c8e4b84c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30f7dccc1823251bafb0dea416bca202c2870b1031e393c845d8f708ea27862eead58392fb6740455cb918785302fb614834bd0b7c05db8f3abc13211432bda4
|
7
|
+
data.tar.gz: 2c74e56f900a0d540359ce69ccf25afa232eea4a1a00ca39b8546877dd00d7cd40b1f9976fe5b6998da8f2f986a9b5b4872ec0112c4feb97dde547fbe263fd99
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [1.6.0](https://github.com/shivam091/unit_measurements-rails/compare/v1.5.0...v1.6.0) - 2023-12-10
|
2
|
+
|
3
|
+
### What's new
|
4
|
+
|
5
|
+
- Added tests for `measured_*` methods.
|
6
|
+
|
7
|
+
-----------
|
8
|
+
|
1
9
|
## [1.5.0](https://github.com/shivam091/unit_measurements-rails/compare/v1.4.0...v1.5.0) - 2023-11-27
|
2
10
|
|
3
11
|
### What's new
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ A Rails adaptor that encapsulate measurements and their units in Ruby on Rails.
|
|
14
14
|
## Introduction
|
15
15
|
|
16
16
|
This gem is designed as a Rails integration for the [unit_measurements](https://github.com/shivam091/unit_measurements) gem.
|
17
|
-
It provides an `ActiveRecord` adapter for persisting and retrieving
|
17
|
+
It provides an `ActiveRecord` adapter for persisting and retrieving measurement quantity along with its unit, simplifying complex
|
18
18
|
measurement handling within your Rails applications.
|
19
19
|
|
20
20
|
## Minimum Requirements
|
@@ -42,8 +42,8 @@ Or otherwise simply install it yourself as:
|
|
42
42
|
|
43
43
|
### ActiveRecord
|
44
44
|
|
45
|
-
This gem provides an ActiveRecord integration allowing you to declare measurement
|
46
|
-
corresponding units in your database schema:
|
45
|
+
This gem provides an ActiveRecord integration allowing you to declare measurement
|
46
|
+
attributes along with their corresponding units in your database schema:
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
class CreateCubes < ActiveRecord::Migration[7.0]
|
@@ -76,6 +76,9 @@ cube.length_unit #=> "ft"
|
|
76
76
|
cube.length #=> 5.0 ft
|
77
77
|
```
|
78
78
|
|
79
|
+
Attribute accessor names are expected to have the `_quantity` and `_unit` suffix,
|
80
|
+
and be `DECIMAL` and `VARCHAR` types, respectively, and defaults values are accepted.
|
81
|
+
|
79
82
|
You can specify multiple measurement attributes simultaneously:
|
80
83
|
|
81
84
|
```ruby
|
@@ -84,28 +87,36 @@ class Cube < ActiveRecord::Base
|
|
84
87
|
end
|
85
88
|
```
|
86
89
|
|
87
|
-
|
88
|
-
`
|
89
|
-
|
90
|
-
You can customize the model's quantity and unit accessors by specifying them in the
|
91
|
-
`quantity_attribute_name` and `unit_attribute_name` options, respectively.
|
90
|
+
You can customize the quantity and unit accessors of the measurement attribute by
|
91
|
+
specifying them in the `quantity_attribute_name` and `unit_attribute_name` options,
|
92
|
+
respectively.
|
92
93
|
|
93
94
|
```ruby
|
94
95
|
class CubeWithCustomAccessor < ActiveRecord::Base
|
95
|
-
|
96
|
-
|
96
|
+
measured UnitMeasurements::Length, :length, :width, :height, unit_attribute_name: :size_uom
|
97
|
+
measured UnitMeasurements::Weight, :weight, quantity_attribute_name: :width_quantity
|
97
98
|
end
|
98
99
|
```
|
99
100
|
|
100
101
|
For a more streamlined approach, predefined methods are available for commonly used
|
101
|
-
types
|
102
|
+
types:
|
103
|
+
|
104
|
+
| # | Unit group | Method name |
|
105
|
+
| :- | :---------- | :----------- |
|
106
|
+
| 1 | Length or distance | measured_length |
|
107
|
+
| 2 | Weight or mass | measured_weight |
|
108
|
+
| 3 | Time or duration | measured_time |
|
109
|
+
| 4 | Temperature | measured_temperature |
|
110
|
+
| 5 | Area | measured_area |
|
111
|
+
| 6 | Volume | measured_volume |
|
112
|
+
| 7 | Density | measured_density |
|
102
113
|
|
103
114
|
```ruby
|
104
|
-
class
|
115
|
+
class CubeWithPredefinedMethods < ActiveRecord::Base
|
105
116
|
measured_length :size
|
106
|
-
|
107
|
-
|
108
|
-
|
117
|
+
measured_volume :volume
|
118
|
+
measured_weight :weight
|
119
|
+
measured_density :density
|
109
120
|
end
|
110
121
|
```
|
111
122
|
|
@@ -121,4 +132,4 @@ Contributions to this project are welcomed! To contribute:
|
|
121
132
|
|
122
133
|
## License
|
123
134
|
|
124
|
-
Copyright 2023 [Harshal V. LADHE](
|
135
|
+
Copyright 2023 [Harshal V. LADHE](https://shivam091.github.io), Released under the [MIT License](http://opensource.org/licenses/MIT).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unit_measurements-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Harshal LADHE
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|