Skip to content

Commit

Permalink
Switched to ActiveSupport::Inflector#underscore as ActiveModel::Name#…
Browse files Browse the repository at this point in the history
…underscore seems to have gone
  • Loading branch information
parndt committed Jul 25, 2012
1 parent 27de76c commit 204c0c6
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions core/lib/refinery/core.rb
Expand Up @@ -102,7 +102,10 @@ def deprecate(what, options = {})

# See if we can trace where this happened
if options[:caller]
whos_calling = options[:caller].detect{|c| c =~ %r{#{Rails.root.to_s}}}.inspect.to_s.split(':in').first
whos_calling = options[:caller].detect{|c|
%r{#{Rails.root.to_s}} === c
}.inspect.to_s.split(':in').first

warning << "\nCalled from: #{whos_calling}\n"
end

Expand Down Expand Up @@ -155,13 +158,16 @@ def route_for_model(klass, options = {})
options = {:plural => false, :admin => true}.merge options

klass = klass.constantize if klass.respond_to?(:constantize)
active_name = ActiveModel::Name.new klass, (Refinery if klass.parents.include?(Refinery))
active_name = ::ActiveModel::Name.new(
klass, (Refinery if klass.parents.include?(Refinery))
)

if options[:admin]
# Most of the time this gets rid of 'refinery'
parts = active_name.underscore.split('/').reject{|name|
active_name.singular_route_key.exclude?(name)
}
parts = ActiveSupport::Inflector.underscore(active_name)
.split('/').reject{|name|
active_name.singular_route_key.exclude?(name)
}

# Get the singular resource_name from the url parts
resource_name = parts.pop
Expand All @@ -176,15 +182,18 @@ def route_for_model(klass, options = {})
end

def include_once(base, extension_module)
base.send :include, extension_module unless included_extension_module?(base, extension_module)
unless included_extension_module?(base, extension_module)
base.send :include, extension_module
end
end

private
# plain Module#included? or Module#included_modules doesn't cut it here
def included_extension_module?(base, extension_module)
if base.kind_of?(Class)
direct_superclass = base.superclass
base.ancestors.take_while {|ancestor| ancestor != direct_superclass}.include?(extension_module)
base.ancestors.take_while {|ancestor| ancestor != direct_superclass}
.include? extension_module
else
base < extension_module # can't do better than that for modules
end
Expand Down

0 comments on commit 204c0c6

Please sign in to comment.