Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast boolean values #45

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Cast boolean values #45

wants to merge 9 commits into from

Conversation

i7an
Copy link

@i7an i7an commented Nov 22, 2024

Boolean methods return raw values. AWS Parameters Store does not support boolean type.

Global.foo.enabled? # => "false"

if Global.foo.enabled? # "false" is truthy
  # ...
end

In this PR I attempted to address this problem:

Global.foo.enabled # => "false"
Global.foo.enabled.class # => String
Global.foo.enabled? # => false
Global.foo.enabled?.calss # => FalseClass

require 'rubygems'
require 'bundler'

Bundler.require
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://bundler.io/guides/bundler_setup.html

For such a small Gemfile, we’d advise you to skip Bundler.require and just require the gems by hand

@@ -1,12 +1,7 @@
# frozen_string_literal: true

require 'rubygems'
require 'bundler'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not find why these were needed.

@@ -95,7 +95,7 @@ def load_parameters_from_ssm(next_token = nil)
def build_configuration_from_parameters(parameters)
configuration = {}
parameters.each do |parameter|
parameter_parts = parameter.name[@prefix.length..-1].split(PATH_SEPARATOR).map(&:to_sym)
parameter_parts = parameter.name[@prefix.length..].split(PATH_SEPARATOR).map(&:to_sym)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rubocop autofix. applies to other as well.

'off', :off,
'OFF', :OFF
].to_set.freeze
private_constant :FALSE_VALUES
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FALSE_VALUES is implementation details and should not be exposed.

normalized_method = normalize_key_by_method(method)
if key?(normalized_method)
value = get_configuration_value(normalized_method)
boolean_method?(method) ? cast_boolean(value) : value
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what this PR is all about.

require 'aws-sdk-ssm'
require 'global/backend/aws_parameter_store'

RSpec.describe Global::Backend::AwsParameterStore do
subject(:parameter_store) do
described_class.new(prefix: '/testapp/', client: client)
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed rubocop abuses. applies to other spec files.

@@ -1,9 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec and lib directories are in the load path by default

@@ -1,9 +1,5 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rspec/core is loaded by default

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'global'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simplecov should be required before any code is loaded
https://github.com/simplecov-ruby/simplecov?tab=readme-ov-file#troubleshooting

Copy link
Member

@leonid-shevtsov leonid-shevtsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the ruby version range is acceptable, seeing as 3.0 is already EOL

- 3.3
- 3.2
- 3.1
- 3.0
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants