two more places: make it possible for plugins to add methods to classes that don't follow naming conventions

This commit is contained in:
Neil Lalonde 2015-11-04 14:53:45 -05:00
parent ef2f77339a
commit abeac7f681
1 changed files with 2 additions and 2 deletions

View File

@ -49,7 +49,7 @@ class Plugin::Instance
delegate :name, to: :metadata delegate :name, to: :metadata
def add_to_serializer(serializer, attr, define_include_method=true, &block) def add_to_serializer(serializer, attr, define_include_method=true, &block)
klass = "#{serializer.to_s.classify}Serializer".constantize klass = "#{serializer.to_s.classify}Serializer".constantize rescue "#{serializer.to_s}Serializer".constantize
klass.attributes(attr) unless attr.to_s.start_with?("include_") klass.attributes(attr) unless attr.to_s.start_with?("include_")
@ -65,7 +65,7 @@ class Plugin::Instance
# Extend a class but check that the plugin is enabled # Extend a class but check that the plugin is enabled
# for class methods use `add_class_method` # for class methods use `add_class_method`
def add_to_class(klass, attr, &block) def add_to_class(klass, attr, &block)
klass = klass.to_s.classify.constantize klass = klass.to_s.classify.constantize rescue klass.to_s.constantize
hidden_method_name = :"#{attr}_without_enable_check" hidden_method_name = :"#{attr}_without_enable_check"
klass.send(:define_method, hidden_method_name, &block) klass.send(:define_method, hidden_method_name, &block)