Module: ActiveType::RecordExtension::Inheritance::ClassMethods
- Defined in:
- lib/active_type/record_extension/inheritance.rb
Instance Method Summary collapse
- #descends_from_active_record? ⇒ Boolean
- #has_many(name, *args, &extension) ⇒ Object
- #has_one(name, *args, &extension) ⇒ Object
- #model_name ⇒ Object
- #module_ancestors ⇒ Object
- #sti_name ⇒ Object
Instance Method Details
#descends_from_active_record? ⇒ Boolean
63 64 65 |
# File 'lib/active_type/record_extension/inheritance.rb', line 63 def descends_from_active_record? extended_record_base_class.descends_from_active_record? end |
#has_many(name, *args, &extension) ⇒ Object
67 68 69 |
# File 'lib/active_type/record_extension/inheritance.rb', line 67 def has_many(name, *args, &extension) super(name, *Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension) end |
#has_one(name, *args, &extension) ⇒ Object
71 72 73 |
# File 'lib/active_type/record_extension/inheritance.rb', line 71 def has_one(name, *args, &extension) super(name, *Inheritance.add_foreign_key_option(extended_record_base_class, *args), &extension) end |
#model_name ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_type/record_extension/inheritance.rb', line 30 def model_name @_model_name ||= begin if name # Namespace detection copied from ActiveModel::Naming namespace = module_ancestors.detect do |n| n.respond_to?(:use_relative_model_naming?) && n.use_relative_model_naming? end # We create a Name object, with the parent class name, but self as the @klass reference # This way lookup_ancestors is invoked on the right class instead of the extended_record_base_class dup_model_name = ActiveModel::Name.new(self, namespace, extended_record_base_class.name) key = name.underscore # We fake the `i18n_key` to lookup on the derived class key # We keep the others the same to preserve parameter and route names dup_model_name.define_singleton_method(:i18n_key) { key } dup_model_name else # name is nil for the anonymous intermediate class extended_record_base_class.model_name end end end |
#module_ancestors ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/active_type/record_extension/inheritance.rb', line 51 def module_ancestors if extended_record_base_class.respond_to?(:module_parents) extended_record_base_class.module_parents else extended_record_base_class.parents end end |
#sti_name ⇒ Object
59 60 61 |
# File 'lib/active_type/record_extension/inheritance.rb', line 59 def sti_name extended_record_base_class.sti_name end |