Skip to content

Commit

Permalink
Naming
Browse files Browse the repository at this point in the history
  • Loading branch information
Exterm1nate committed Feb 20, 2025
1 parent e3b4e36 commit 90b0110
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/models/concerns/active_fields/customizable_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def active_fields
ActiveFields.config.field_base_class.for(model_name.name)
end

def available_field_types
ActiveFields.registry.field_types_for(model_name.name) || []
def available_field_type_names
ActiveFields.registry.field_type_names_for(model_name.name).to_a
end

def available_field_class_names
ActiveFields.config.fields.values_at(*available_field_types)
ActiveFields.config.fields.values_at(*available_field_type_names)
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/models/concerns/active_fields/field_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def type_name
end

def available_customizable_types
ActiveFields.registry.customizable_types_for(type_name) || []
ActiveFields.registry.customizable_types_for(type_name).to_a
end

private
Expand All @@ -111,8 +111,8 @@ def validate_default_value
end

def validate_customizable_model_allows_type
allowed_types = ActiveFields.registry.field_types_for(customizable_type) || []
return true if allowed_types.include?(type_name)
allowed_type_names = ActiveFields.registry.field_type_names_for(customizable_type).to_a
return true if allowed_type_names.include?(type_name)

errors.add(:customizable_type, :inclusion)
false
Expand Down
18 changes: 9 additions & 9 deletions lib/active_fields/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ def initialize
@customizables = {}
end

def add(field_type, customizable_type)
if ActiveFields.config.type_names.exclude?(field_type)
raise ArgumentError, "undefined ActiveFields type provided for #{customizable_type}: #{field_type}"
def add(field_type_name, customizable_type)
if ActiveFields.config.type_names.exclude?(field_type_name)
raise ArgumentError, "undefined ActiveFields type provided for #{customizable_type}: #{field_type_name}"
end

@fields[field_type] ||= Set.new
@fields[field_type] << customizable_type
@fields[field_type_name] ||= Set.new
@fields[field_type_name] << customizable_type

@customizables[customizable_type] ||= Set.new
@customizables[customizable_type] << field_type
@customizables[customizable_type] << field_type_name

nil
end

def customizable_types_for(field_type)
@fields[field_type]
def customizable_types_for(field_type_name)
@fields[field_type_name]
end

def field_types_for(customizable_type)
def field_type_names_for(customizable_type)
@customizables[customizable_type]
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
config.enable_reloading = true

# Do not eager load code on boot.
config.eager_load = true
config.eager_load = false

# Show full error reports.
config.consider_all_requests_local = true
Expand Down

0 comments on commit 90b0110

Please sign in to comment.