Skip to content

Commit

Permalink
Merge pull request #11 from bdurand/fix_namespace_conflicts
Browse files Browse the repository at this point in the history
Fix namespace conflicts
  • Loading branch information
bdurand authored Sep 28, 2024
2 parents 191c383 + 87583ad commit 456bf45
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.0.0

### Fixed

- **Breaking Change:** Fix conflict with overridding the standard `include?` method on configuration classes. These methods are now defined as `UltraSettings.added?` and `UltraSettings::Configuration.include_field?`.
- **Breaking Change:** Include namespace in autoloaded configuration names for Rails applications to avoid conflicts on classes in different namespaces.

### Changed

- Use configuration class in in web UI dropdown menu.

## 1.1.2

### Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
2.0.0
4 changes: 2 additions & 2 deletions app/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="ultra-settings-nav">
<form onsubmit="return false">
<form onsubmit="return false" style="margin-bottom: 0.5rem;">
<select class="<%= html_escape(select_class) %>" size="1" id="config-selector">
<% UltraSettings.__configuration_names__.sort.each do |name| %>
<option value="config-<%= html_escape(name) %>"><%= html_escape(name) %></option>
<option value="config-<%= html_escape(name) %>"><%= html_escape(UltraSettings.send(name).class.name) %></option>
<% end %>
</select>
</form>
Expand Down
Binary file modified assets/web_ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions lib/ultra_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class << self
def add(name, klass = nil)
name = name.to_s
unless name.match?(VALID_NAME__PATTERN)
raise ArgementError.new("Invalid configuration name: #{name.inspect}")
raise ArgumentError.new("Invalid configuration name: #{name.inspect}")
end

class_name = klass&.to_s
Expand All @@ -67,7 +67,7 @@ def #{name}
#
# @param class_name [Class, String] The name of the configuration class.
# @return [Boolean]
def include?(class_name)
def added?(class_name)
@configurations.values.collect(&:to_s).include?(class_name.to_s)
end

Expand Down
6 changes: 3 additions & 3 deletions lib/ultra_settings/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ def fields
#
# @param name [Symbol, String] The name of the field.
# @return [Boolean]
def include?(name)
def include_field?(name)
name = name.to_s
return true if defined_fields.include?(name)

if superclass <= Configuration
superclass.include?(name)
superclass.include_field?(name)
else
false
end
Expand Down Expand Up @@ -446,7 +446,7 @@ def [](name)
end

def include?(name)
self.class.include?(name.to_s)
self.class.include_field?(name.to_s)
end

def override!(values, &block)
Expand Down
9 changes: 6 additions & 3 deletions lib/ultra_settings/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class Railtie < Rails::Railtie

app_config_dir = Rails.root.join(directory)
app_config_dir.glob("**/*_configuration.rb").each do |file_path|
config_name = file_path.basename("_configuration.rb")
class_name = file_path.relative_path_from(app_config_dir).to_s.chomp(".rb").classify
UltraSettings.add(config_name, class_name)
relative_path = file_path.relative_path_from(app_config_dir).to_s
class_name = relative_path.chomp(".rb").classify
unless UltraSettings.added?(class_name)
config_name = class_name.delete_suffix("Configuration").underscore.tr("/", "_")
UltraSettings.add(config_name, class_name)
end
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/ultra_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

it "can detect if a class has been added" do
UltraSettings.test
expect(UltraSettings.include?(TestConfiguration)).to be(true)
expect(UltraSettings.include?("TestConfiguration")).to be(true)
expect(UltraSettings.include?(Object)).to be(false)
expect(UltraSettings.added?(TestConfiguration)).to be(true)
expect(UltraSettings.added?("TestConfiguration")).to be(true)
expect(UltraSettings.added?(Object)).to be(false)
end
end

Expand Down

0 comments on commit 456bf45

Please sign in to comment.