measured 2.5.2 → 2.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.

Potentially problematic release.


This version of measured might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce0f6c7c10571db0dd0d844638dd0bae637d2f9b13e87c29700bf9db51d84197
4
- data.tar.gz: 936e5b74c36c65ca8393b94684b13341ff84d6981cfa34379af9cd0f8bdbed94
3
+ metadata.gz: 2de9a5e120aaab53f71956ad225722ed2d5cdd01d018104b214af063eb22b149
4
+ data.tar.gz: f65f75ed06c7118f76da05d638782c8b0049f928e6ce0ce96f93e27673d3dd48
5
5
  SHA512:
6
- metadata.gz: 95eea761fff7e89716925729c8dae771b6274705390622930cf58443bc1d18bd2405bc65b13fa46b1c232ad249a231b0c1d5d7bedafa5d8262f860d94ac24437
7
- data.tar.gz: b9d5ed9a9dc1a0fe8710a62c6c7d673d53c4fee4161f76452ab1f1b708edcb1a8ca081577dd4fb012358b375952d675f8e0bfc8d253f5b8519a024c944806bf1
6
+ metadata.gz: c445792e2670c86ab8526ba7021880c6bef7db3850be768aae8a54ff024b4e56816b24cd4df88f6748971b7e176bb5eceefa48234511d9fbb25f67a065966733
7
+ data.tar.gz: 3eae614b358b735a68a6d8a17088f252d7f9db11db3f31c8cbc2a3e4e54d1ac0441d0af2d2f69a44bcbe2654c8839356ac00bc6b7c929d6c3e857f7afbc91d6e
@@ -0,0 +1,31 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ env:
9
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
10
+ strategy:
11
+ matrix:
12
+ ruby:
13
+ - 2.5
14
+ - 2.6
15
+ - 2.7
16
+ gemfile:
17
+ - Gemfile
18
+ - gemfiles/activesupport-5.2.gemfile
19
+ - gemfiles/activesupport-6.0.gemfile
20
+ - gemfiles/activesupport-6.1.gemfile
21
+ name: Ruby ${{ matrix.ruby }} ${{ matrix.gemfile }}
22
+ steps:
23
+ - uses: actions/checkout@v1
24
+ - name: Set up Ruby ${{ matrix.ruby }}
25
+ uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ bundler-cache: true
29
+ - name: Run tests
30
+ run: |
31
+ bundle exec rake
@@ -1,3 +1,10 @@
1
+ 2.6.0
2
+ -----
3
+
4
+ * Add `Measured::MissingConversionPath` and `Measured::UnitAlreadyAdded` as subclasses of `Measured::UnitError` to handle specific error cases. (@arturopie)
5
+ * Support only ActiveSupport 5.2 and above.
6
+
7
+
1
8
  2.5.2
2
9
  -----
3
10
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Measured [![Build Status](https://travis-ci.org/Shopify/measured.svg)](https://travis-ci.org/Shopify/measured) [![Gem Version](https://badge.fury.io/rb/measured.svg)](http://badge.fury.io/rb/measured)
1
+ # Measured [![Build Status](https://github.com/Shopify/measured/workflows/CI/badge.svg)](https://github.com/Shopify/measured/actions?query=workflow%3ACI)
2
2
 
3
3
  Encapsulates measurements with their units. Provides easy conversion between units. Built in support for weight, length, and volume.
4
4
 
@@ -273,12 +273,13 @@ Existing alternatives which were considered:
273
273
 
274
274
  ### Gem: [unitwise](https://github.com/joshwlewis/unitwise)
275
275
  * **Pros**
276
- * Well written and maintained.
276
+ * Well written.
277
277
  * Conversions done with Unified Code for Units of Measure (UCUM) so highly accurate and reliable.
278
278
  * **Cons**
279
279
  * Lots of code. Good code, but lots of it.
280
280
  * Many modifications to core types.
281
281
  * ActiveRecord adapter exists but is written and maintained by a different person/org.
282
+ * Not actively maintained.
282
283
 
283
284
  ## Contributing
284
285
 
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activesupport', '~> 5.0'
5
+ gem 'activesupport', '~> 5.2'
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activesupport', '~> 6.0.0.rc1'
5
+ gem 'activesupport', '~> 6.0'
@@ -2,4 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'activesupport', '~> 5.1'
5
+ gem 'activesupport', '~> 6.1'
@@ -6,8 +6,6 @@ require "bigdecimal"
6
6
  require "json"
7
7
 
8
8
  module Measured
9
- class UnitError < StandardError ; end
10
-
11
9
  class << self
12
10
  def build(&block)
13
11
  builder = UnitSystemBuilder.new
@@ -39,6 +37,9 @@ module Measured
39
37
  end
40
38
  end
41
39
 
40
+ require "measured/unit_error"
41
+ require "measured/unit_already_added"
42
+ require "measured/missing_conversion_path"
42
43
  require "measured/arithmetic"
43
44
  require "measured/parser"
44
45
  require "measured/unit"
@@ -40,7 +40,7 @@ class Measured::ConversionTableBuilder
40
40
  def find_conversion(to:, from:)
41
41
  conversion = find_direct_conversion_cached(to: to, from: from) || find_tree_traversal_conversion(to: to, from: from)
42
42
 
43
- raise Measured::UnitError, "Cannot find conversion path from #{ from } to #{ to }." unless conversion
43
+ raise Measured::MissingConversionPath.new(from, to) unless conversion
44
44
 
45
45
  conversion
46
46
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Measured
3
+ class MissingConversionPath < UnitError
4
+ attr_reader :from, :to
5
+
6
+ def initialize(from, to)
7
+ super("Cannot find conversion path from #{from} to #{to}.")
8
+ @from = from
9
+ @to = to
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module Measured
3
+ class UnitAlreadyAdded < UnitError
4
+ attr_reader :unit_name
5
+
6
+ def initialize(unit_name)
7
+ super("Unit #{unit_name} has already been added.")
8
+ @unit_name = unit_name
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module Measured
3
+ class UnitError < StandardError ; end
4
+ end
@@ -67,7 +67,7 @@ class Measured::UnitSystemBuilder
67
67
  def check_for_duplicate_unit_names!(unit)
68
68
  names = @units.flat_map(&:names)
69
69
  if names.any? { |name| unit.names.include?(name) }
70
- raise Measured::UnitError, "Unit #{unit.name} has already been added."
70
+ raise Measured::UnitAlreadyAdded.new(unit.name)
71
71
  end
72
72
  end
73
73
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Measured
3
- VERSION = "2.5.2"
3
+ VERSION = "2.6.0"
4
4
  end
@@ -13,12 +13,20 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/Shopify/measured"
14
14
  spec.license = "MIT"
15
15
 
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
16
24
  spec.files = `git ls-files -z`.split("\x0")
17
25
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
26
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
27
  spec.require_paths = ["lib"]
20
28
 
21
- spec.add_runtime_dependency "activesupport", ">= 5.0"
29
+ spec.add_runtime_dependency "activesupport", ">= 5.2"
22
30
 
23
31
  spec.add_development_dependency "rake", "> 10.0"
24
32
  spec.add_development_dependency "minitest", "> 5.5.1"
@@ -12,15 +12,17 @@ class Measured::UnitSystemBuilderTest < ActiveSupport::TestCase
12
12
  end
13
13
 
14
14
  test "#unit cannot add duplicate unit names" do
15
- assert_raises Measured::UnitError do
15
+ error = assert_raises Measured::UnitAlreadyAdded do
16
16
  Measured.build do
17
17
  unit :m
18
18
  unit :in, aliases: [:inch], value: "0.0254 m"
19
19
  unit :in, aliases: [:thing], value: "123 m"
20
20
  end
21
21
  end
22
+ assert_equal("in", error.unit_name)
23
+ assert_equal("Unit in has already been added.", error.message)
22
24
 
23
- assert_raises Measured::UnitError do
25
+ assert_raises Measured::UnitAlreadyAdded do
24
26
  Measured.build do
25
27
  unit :m
26
28
  unit :in, aliases: [:inch], value: "0.0254 m"
@@ -29,6 +31,19 @@ class Measured::UnitSystemBuilderTest < ActiveSupport::TestCase
29
31
  end
30
32
  end
31
33
 
34
+ test "#unit raises when cannot find conversion path" do
35
+ error = assert_raises Measured::MissingConversionPath do
36
+ Measured.build do
37
+ unit :m
38
+ unit :in, value: "0.0254 m"
39
+ unit :pallets, value: "5 cases"
40
+ end
41
+ end
42
+ assert_equal("pallets", error.from)
43
+ assert_equal("m", error.to)
44
+ assert_equal("Cannot find conversion path from pallets to m.", error.message)
45
+ end
46
+
32
47
  test "#unit is case sensitive" do
33
48
  measurable = Measured.build do
34
49
  unit :normal
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measured
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McPhillips
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-01-08 00:00:00.000000000 Z
13
+ date: 2020-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: '5.0'
21
+ version: '5.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: '5.0'
28
+ version: '5.2'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -104,8 +104,8 @@ executables: []
104
104
  extensions: []
105
105
  extra_rdoc_files: []
106
106
  files:
107
+ - ".github/workflows/ci.yml"
107
108
  - ".gitignore"
108
- - ".travis.yml"
109
109
  - CHANGELOG.md
110
110
  - Gemfile
111
111
  - LICENSE
@@ -116,9 +116,9 @@ files:
116
116
  - cache/volume.json
117
117
  - cache/weight.json
118
118
  - dev.yml
119
- - gemfiles/activesupport-5.0.gemfile
120
- - gemfiles/activesupport-5.1.gemfile
119
+ - gemfiles/activesupport-5.2.gemfile
121
120
  - gemfiles/activesupport-6.0.gemfile
121
+ - gemfiles/activesupport-6.1.gemfile
122
122
  - lib/measured.rb
123
123
  - lib/measured/arithmetic.rb
124
124
  - lib/measured/base.rb
@@ -127,8 +127,11 @@ files:
127
127
  - lib/measured/cache/null.rb
128
128
  - lib/measured/conversion_table_builder.rb
129
129
  - lib/measured/measurable.rb
130
+ - lib/measured/missing_conversion_path.rb
130
131
  - lib/measured/parser.rb
131
132
  - lib/measured/unit.rb
133
+ - lib/measured/unit_already_added.rb
134
+ - lib/measured/unit_error.rb
132
135
  - lib/measured/unit_system.rb
133
136
  - lib/measured/unit_system_builder.rb
134
137
  - lib/measured/units/length.rb
@@ -159,7 +162,8 @@ files:
159
162
  homepage: https://github.com/Shopify/measured
160
163
  licenses:
161
164
  - MIT
162
- metadata: {}
165
+ metadata:
166
+ allowed_push_host: https://rubygems.org
163
167
  post_install_message:
164
168
  rdoc_options: []
165
169
  require_paths:
@@ -1,17 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- cache: bundler
4
- rvm:
5
- - 2.4.9
6
- - 2.5.7
7
- - 2.6.5
8
- - 2.7.0
9
- gemfile:
10
- - Gemfile
11
- - gemfiles/activesupport-5.0.gemfile
12
- - gemfiles/activesupport-5.1.gemfile
13
- - gemfiles/activesupport-6.0.gemfile
14
- matrix:
15
- exclude:
16
- - gemfile: gemfiles/activesupport-6.0.gemfile
17
- rvm: 2.4.9