-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from shivam091/5.3.0
5.3.0
- Loading branch information
Showing
10 changed files
with
258 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
unit_measurements (5.2.0) | ||
unit_measurements (5.3.0) | ||
activesupport (~> 7.0) | ||
|
||
GEM | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_stringing_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
module UnitMeasurements | ||
# The +UnitMeasurements::Configuration+ class maintains and manages the globally | ||
# configurable options of +*unit_measurements*+. | ||
# | ||
# @note | ||
# This class is responsible for configuring globally configurable options of | ||
# +*unit_measurements*+. | ||
# | ||
# @author {Harshal V. Ladhe}[https://shivam091.github.io/] | ||
# @since 5.3.0 | ||
class Configuration | ||
# Get the current value of the +use_cache+ option. | ||
# | ||
# @note | ||
# This option controls whether caching is enabled for converting measurements. | ||
# Defaults to +false+. | ||
# | ||
# @return [TrueClass|FalseClass] | ||
# Returns +true+ if caching is enabled, otherwise +false+. | ||
# | ||
# @see Cache | ||
# @author {Harshal V. Ladhe}[https://shivam091.github.io/] | ||
# @since 5.3.0 | ||
attr_reader :use_cache | ||
|
||
# Initializes a new +Configuration+ instance with default values of configurable | ||
# options. | ||
# | ||
# @author {Harshal V. Ladhe}[https://shivam091.github.io/] | ||
# @since 5.3.0 | ||
def initialize | ||
self.use_cache = false | ||
end | ||
|
||
# Sets a value for the +use_cache+ option. | ||
# | ||
# It controls whether caching is enabled for converting measurements. When | ||
# caching is enabled, previously computed conversion factors are stored for | ||
# future use, improving conversion performance. | ||
# | ||
# @param [TrueClass|FalseClass] use_cache | ||
# +true+ if caching should be used while converting the measurement otherwise | ||
# +false+. | ||
# | ||
# @return [TrueClass|FalseClass] The updated value of +use_cache+. | ||
# | ||
# @raise [BaseError] if +use_cache+ is not a boolean value. | ||
# | ||
# @see Cache | ||
# @author {Harshal V. Ladhe}[https://shivam091.github.io/] | ||
# @since 5.3.0 | ||
def use_cache=(use_cache) | ||
unless [true, false].include?(use_cache) | ||
raise BaseError, "Configuration#use_cache= only accepts true or false, but received #{use_cache}" | ||
end | ||
|
||
@use_cache = use_cache | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ | |
|
||
module UnitMeasurements | ||
# Current stable version. | ||
VERSION = "5.2.0" | ||
VERSION = "5.3.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- encoding: utf-8 -*- | ||
# -*- frozen_string_literal: true -*- | ||
# -*- warn_indent: true -*- | ||
|
||
# spec/unit_measurements/configuration_spec.rb | ||
|
||
RSpec.describe UnitMeasurements::Configuration do | ||
describe "#initialize" do | ||
it "sets default values of configurable options" do | ||
config = described_class.new | ||
|
||
expect(config.use_cache).to be_falsey | ||
end | ||
end | ||
|
||
describe "#use_cache=" do | ||
it "sets use_cache to true" do | ||
config = described_class.new | ||
config.use_cache = true | ||
|
||
expect(config.use_cache).to be_truthy | ||
end | ||
|
||
it "sets use_cache to false" do | ||
config = described_class.new | ||
config.use_cache = false | ||
|
||
expect(config.use_cache).to be_falsey | ||
end | ||
|
||
it "raises BaseError for invalid input" do | ||
config = described_class.new | ||
|
||
expect { config.use_cache = "invalid" }.to raise_error(UnitMeasurements::BaseError, /only accepts true or false/) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters