Skip to content

Commit

Permalink
Allow for namespaced models.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmhawash committed Dec 2, 2024
1 parent 1d64ef2 commit a59b2a1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/decent_exposure/behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def scope(model)
#
# Returns a standard Class name.
def model
name.to_s.classify.constantize
[model_namespace, name.to_s.classify].compact.join('::').constantize
end

# Public: Find an object on the supplied scope.
Expand Down Expand Up @@ -84,6 +84,10 @@ def build_params
end

protected
def model_namespace
options[:model_namespace].to_s
end


def params_id_key_candidates
["#{model_param_key}_id", "#{name}_id", "id"].uniq
Expand Down
7 changes: 7 additions & 0 deletions lib/decent_exposure/exposure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def normalize_options
normalize_parent_option
normalize_from_option
normalize_find_by_option
normalize_model_namespace_option
end

def normalize_fetch_option
Expand Down Expand Up @@ -138,6 +139,12 @@ def normalize_model_option
end
end

def normalize_model_namespace_option
normalize_non_proc_option :model_namespace do |value|
-> { value.to_s }
end
end

def normalize_build_params_option
normalize_non_proc_option :build_params do |value|
options[:build_params_method] = value
Expand Down
2 changes: 1 addition & 1 deletion lib/decent_exposure/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module DecentExposure
VERSION = "3.0.4"
VERSION = "3.0.5"
end

0 comments on commit a59b2a1

Please sign in to comment.