unit_measurements-rails 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/lib/unit_measurements/rails/active_record.rb +2 -0
- data/lib/unit_measurements/rails/unit_groups/all.rb +5 -2
- data/lib/unit_measurements/rails/unit_groups/area.rb +1 -1
- data/lib/unit_measurements/rails/unit_groups/density.rb +50 -0
- data/lib/unit_measurements/rails/unit_groups/length.rb +1 -1
- data/lib/unit_measurements/rails/unit_groups/temperature.rb +50 -0
- data/lib/unit_measurements/rails/unit_groups/time.rb +50 -0
- data/lib/unit_measurements/rails/unit_groups/volume.rb +1 -1
- data/lib/unit_measurements/rails/unit_groups/weight.rb +1 -1
- data/lib/unit_measurements/rails/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf20e075bf5db7bd8a33f60eb2e14493aa4ed985defd4a3f49b020498a66ec6b
|
4
|
+
data.tar.gz: df3f2e54ed849cab6b0b6e7221e57bc74c11480053136aba222f6f91b3c43410
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a59d3f2cd7a3d7f716aa68ba88ff3c19ae29aade038c6aa1258a5eeef77c6fc44634e3c66167b8e9e499865c51b15861f0122e3cb6b226d1414daa8cb18af14
|
7
|
+
data.tar.gz: 3c722fab2b67d36ae090aef75a01222e5bbecf937c9a2322c03832a4960e0304975d9a347eef5178ea94cc5ae184f5055f97436e37a5702a1ded9b5cbebd5cc2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## [1.3.0](https://github.com/shivam091/unit_measurements-rails/compare/v1.2.0...v1.3.0) - 2023-11-22
|
2
|
+
|
3
|
+
### What's new
|
4
|
+
|
5
|
+
- Raise `BaseError` if already measured attribute.
|
6
|
+
- Added wrapper for defining `density` measured attributes.
|
7
|
+
- Added wrapper for defining `temperature` measured attributes.
|
8
|
+
- Added wrapper for defining `time` measured attributes.
|
9
|
+
|
10
|
+
-----------
|
11
|
+
|
1
12
|
## [1.2.0](https://github.com/shivam091/unit_measurements-rails/compare/v1.1.0...v1.2.0) - 2023-11-20
|
2
13
|
|
3
14
|
### What's new
|
data/Gemfile.lock
CHANGED
@@ -60,6 +60,8 @@ module UnitMeasurements
|
|
60
60
|
options[:unit_group] = unit_group
|
61
61
|
|
62
62
|
measured_attrs.map(&:to_s).each do |measured_attr|
|
63
|
+
raise BaseError, "The field '#{measured_attr}' has already been measured." if measured_attributes.key?(measured_attr)
|
64
|
+
|
63
65
|
quantity_attr = options[:quantity_attribute_name]&.to_s || "#{measured_attr}_quantity"
|
64
66
|
unit_attr = options[:unit_attribute_name]&.to_s || "#{measured_attr}_unit"
|
65
67
|
|
@@ -2,7 +2,10 @@
|
|
2
2
|
# -*- frozen_string_literal: true -*-
|
3
3
|
# -*- warn_indent: true -*-
|
4
4
|
|
5
|
+
require_relative "area"
|
6
|
+
require_relative "density"
|
5
7
|
require_relative "length"
|
6
|
-
require_relative "
|
8
|
+
require_relative "temperature"
|
9
|
+
require_relative "time"
|
7
10
|
require_relative "volume"
|
8
|
-
require_relative "
|
11
|
+
require_relative "weight"
|
@@ -16,7 +16,7 @@ module UnitMeasurements::Rails::ActiveRecord::Area
|
|
16
16
|
#
|
17
17
|
# This method serves as a wrapper around the +measured+ method and allows easy
|
18
18
|
# definition of area-measured attributes by accepting an array of attribute
|
19
|
-
# names.
|
19
|
+
# names along with their options.
|
20
20
|
#
|
21
21
|
# @param [Array<String|Symbol>] measured_attrs
|
22
22
|
# An array of the names of area-measured attributes.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
# The +UnitMeasurements::Rails::ActiveRecord::Density+ module provides a convenient
|
6
|
+
# way to define density-measured attributes in +ActiveRecord+ models.
|
7
|
+
#
|
8
|
+
# It acts as a wrapper for the +measured+ method, simplifying the definition of
|
9
|
+
# density-measured attributes without directly invoking the +measured+ method.
|
10
|
+
#
|
11
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
12
|
+
# @since 1.3.0
|
13
|
+
module UnitMeasurements::Rails::ActiveRecord::Density
|
14
|
+
# @!scope class
|
15
|
+
# Defines _density-measured_ attributes in the +ActiveRecord+ model.
|
16
|
+
#
|
17
|
+
# This method serves as a wrapper around the +measured+ method and allows easy
|
18
|
+
# definition of density-measured attributes by accepting an array of attribute
|
19
|
+
# names along with their options.
|
20
|
+
#
|
21
|
+
# @param [Array<String|Symbol>] measured_attrs
|
22
|
+
# An array of the names of density-measured attributes.
|
23
|
+
# @param [Hash] options A customizable set of options
|
24
|
+
# @option options [String|Symbol] :quantity_attribute_name The name of the quantity attribute.
|
25
|
+
# @option options [String|Symbol] :unit_attribute_name The name of the unit attribute.
|
26
|
+
#
|
27
|
+
# @example Define single density-measured attribute:
|
28
|
+
# class Substance < ActiveRecord::Base
|
29
|
+
# measured_density :total_density
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# @example Define multiple density-measured attributes:
|
33
|
+
# class Substance < ActiveRecord::Base
|
34
|
+
# measured_density :internal_density, :external_density
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# @return [void]
|
38
|
+
#
|
39
|
+
# @see .measured
|
40
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
41
|
+
# @since 1.3.0
|
42
|
+
def measured_density(*measured_attrs, **options)
|
43
|
+
measured(UnitMeasurements::Density, *measured_attrs, **options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# ActiveSupport hook to extend ActiveRecord with the `UnitMeasurements::Rails::ActiveRecord::Density` module.
|
48
|
+
ActiveSupport.on_load(:active_record) do
|
49
|
+
::ActiveRecord::Base.send(:extend, UnitMeasurements::Rails::ActiveRecord::Density)
|
50
|
+
end
|
@@ -16,7 +16,7 @@ module UnitMeasurements::Rails::ActiveRecord::Length
|
|
16
16
|
#
|
17
17
|
# This method serves as a wrapper around the +measured+ method and allows easy
|
18
18
|
# definition of length-measured attributes by accepting an array of attribute
|
19
|
-
# names.
|
19
|
+
# names along with their options.
|
20
20
|
#
|
21
21
|
# @param [Array<String|Symbol>] measured_attrs
|
22
22
|
# An array of the names of length-measured attributes.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
# The +UnitMeasurements::Rails::ActiveRecord::Temperature+ module provides a convenient
|
6
|
+
# way to define temperature-measured attributes in +ActiveRecord+ models.
|
7
|
+
#
|
8
|
+
# It acts as a wrapper for the +measured+ method, simplifying the definition of
|
9
|
+
# temperature-measured attributes without directly invoking the +measured+ method.
|
10
|
+
#
|
11
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
12
|
+
# @since 1.3.0
|
13
|
+
module UnitMeasurements::Rails::ActiveRecord::Temperature
|
14
|
+
# @!scope class
|
15
|
+
# Defines _temperature-measured_ attributes in the +ActiveRecord+ model.
|
16
|
+
#
|
17
|
+
# This method serves as a wrapper around the +measured+ method and allows easy
|
18
|
+
# definition of temperature-measured attributes by accepting an array of attribute
|
19
|
+
# names along with their options.
|
20
|
+
#
|
21
|
+
# @param [Array<String|Symbol>] measured_attrs
|
22
|
+
# An array of the names of temperature-measured attributes.
|
23
|
+
# @param [Hash] options A customizable set of options
|
24
|
+
# @option options [String|Symbol] :quantity_attribute_name The name of the quantity attribute.
|
25
|
+
# @option options [String|Symbol] :unit_attribute_name The name of the unit attribute.
|
26
|
+
#
|
27
|
+
# @example Define single temperature-measured attribute:
|
28
|
+
# class WeatherReport < ActiveRecord::Base
|
29
|
+
# measured_temperature :average_temperature
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# @example Define multiple temperature-measured attributes:
|
33
|
+
# class WeatherReport < ActiveRecord::Base
|
34
|
+
# measured_temperature :day_temperature, :night_temperature
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# @return [void]
|
38
|
+
#
|
39
|
+
# @see .measured
|
40
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
41
|
+
# @since 1.3.0
|
42
|
+
def measured_temperature(*measured_attrs, **options)
|
43
|
+
measured(UnitMeasurements::Temperature, *measured_attrs, **options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# ActiveSupport hook to extend ActiveRecord with the `UnitMeasurements::Rails::ActiveRecord::Temperature` module.
|
48
|
+
ActiveSupport.on_load(:active_record) do
|
49
|
+
::ActiveRecord::Base.send(:extend, UnitMeasurements::Rails::ActiveRecord::Temperature)
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# -*- frozen_string_literal: true -*-
|
3
|
+
# -*- warn_indent: true -*-
|
4
|
+
|
5
|
+
# The +UnitMeasurements::Rails::ActiveRecord::Time+ module provides a convenient
|
6
|
+
# way to define time-measured attributes in +ActiveRecord+ models.
|
7
|
+
#
|
8
|
+
# It acts as a wrapper for the +measured+ method, simplifying the definition of
|
9
|
+
# time-measured attributes without directly invoking the +measured+ method.
|
10
|
+
#
|
11
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
12
|
+
# @since 1.3.0
|
13
|
+
module UnitMeasurements::Rails::ActiveRecord::Time
|
14
|
+
# @!scope class
|
15
|
+
# Defines _time-measured_ attributes in the +ActiveRecord+ model.
|
16
|
+
#
|
17
|
+
# This method serves as a wrapper around the +measured+ method and allows easy
|
18
|
+
# definition of time-measured attributes by accepting an array of attribute
|
19
|
+
# names along with their options.
|
20
|
+
#
|
21
|
+
# @param [Array<String|Symbol>] measured_attrs
|
22
|
+
# An array of the names of time-measured attributes.
|
23
|
+
# @param [Hash] options A customizable set of options
|
24
|
+
# @option options [String|Symbol] :quantity_attribute_name The name of the quantity attribute.
|
25
|
+
# @option options [String|Symbol] :unit_attribute_name The name of the unit attribute.
|
26
|
+
#
|
27
|
+
# @example Define single time-measured attribute:
|
28
|
+
# class ProjectTimeline < ActiveRecord::Base
|
29
|
+
# measured_time :duration
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# @example Define multiple time-measured attributes:
|
33
|
+
# class ProjectTimeline < ActiveRecord::Base
|
34
|
+
# measured_time :setup_time, :processing_time
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# @return [void]
|
38
|
+
#
|
39
|
+
# @see .measured
|
40
|
+
# @author {Harshal V. Ladhe}[https://shivam091.github.io/]
|
41
|
+
# @since 1.3.0
|
42
|
+
def measured_time(*measured_attrs, **options)
|
43
|
+
measured(UnitMeasurements::Time, *measured_attrs, **options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# ActiveSupport hook to extend ActiveRecord with the `UnitMeasurements::Rails::ActiveRecord::Time` module.
|
48
|
+
ActiveSupport.on_load(:active_record) do
|
49
|
+
::ActiveRecord::Base.send(:extend, UnitMeasurements::Rails::ActiveRecord::Time)
|
50
|
+
end
|
@@ -16,7 +16,7 @@ module UnitMeasurements::Rails::ActiveRecord::Volume
|
|
16
16
|
#
|
17
17
|
# This method serves as a wrapper around the +measured+ method and allows easy
|
18
18
|
# definition of volume-measured attributes by accepting an array of attribute
|
19
|
-
# names.
|
19
|
+
# names along with their options.
|
20
20
|
#
|
21
21
|
# @param [Array<String|Symbol>] measured_attrs
|
22
22
|
# An array of the names of volume-measured attributes.
|
@@ -16,7 +16,7 @@ module UnitMeasurements::Rails::ActiveRecord::Weight
|
|
16
16
|
#
|
17
17
|
# This method serves as a wrapper around the +measured+ method and allows easy
|
18
18
|
# definition of weight-measured attributes by accepting an array of attribute
|
19
|
-
# names.
|
19
|
+
# names along with their options.
|
20
20
|
#
|
21
21
|
# @param [Array<String|Symbol>] measured_attrs
|
22
22
|
# An array of the names of weight-measured attributes.
|
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.3.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-
|
11
|
+
date: 2023-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -170,7 +170,10 @@ files:
|
|
170
170
|
- lib/unit_measurements/rails/railtie.rb
|
171
171
|
- lib/unit_measurements/rails/unit_groups/all.rb
|
172
172
|
- lib/unit_measurements/rails/unit_groups/area.rb
|
173
|
+
- lib/unit_measurements/rails/unit_groups/density.rb
|
173
174
|
- lib/unit_measurements/rails/unit_groups/length.rb
|
175
|
+
- lib/unit_measurements/rails/unit_groups/temperature.rb
|
176
|
+
- lib/unit_measurements/rails/unit_groups/time.rb
|
174
177
|
- lib/unit_measurements/rails/unit_groups/volume.rb
|
175
178
|
- lib/unit_measurements/rails/unit_groups/weight.rb
|
176
179
|
- lib/unit_measurements/rails/version.rb
|