Module: Jsapi::Model::Naming

Includes:
ActiveModel::Naming, ActiveModel::Translation
Included in:
Base
Defined in:
lib/jsapi/model/naming.rb

Instance Method Summary collapse

Instance Method Details

#model_nameObject

Overrides ActiveModel::Naming#model_name to support anonymous model classes.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jsapi/model/naming.rb', line 11

def model_name
  @_model_name ||= begin
    # Copied from ActiveModel::Naming#model_name
    namespace = module_parents.detect do |m|
      m.respond_to?(:use_relative_model_naming?) &&
        m.use_relative_model_naming?
    end
    # Prevent that ActiveModel::Name::new raises an error if this is
    # an anonymous class
    klass = self
    klass = klass.superclass while klass.name.nil?

    ActiveModel::Name.new(klass, namespace)
  end
end