Sha256: 71e1271869a67b3e9d3740f6f62bdb0b3f68d4ec47083ddd2658c7a7452a28cf

Contents?: true

Size: 610 Bytes

Versions: 3

Compression:

Stored size: 610 Bytes

Contents

module ActiveHashRelation
  module Helpers
    def model_class_name(resource, _engine = false)
      _class = resource.class.to_s.split('::')
      if _engine === true
        "#{_class[0]}::#{_class[1]}".constantize
      else
        _class.first.constantize
      end
    end

    def engine_name
      Rails::Engine.subclasses[0].to_s.split('::').first
    end

    def find_model(model)
      return model if model

      model = model_class_name(@resource)
      if model.nil? || engine_name == model.to_s
        model = model_class_name(@resource, true)
      end

      return model
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_hash_relation-1.4.1 lib/active_hash_relation/helpers.rb
active_hash_relation-1.4.0 lib/active_hash_relation/helpers.rb
active_hash_relation-1.2.0 lib/active_hash_relation/helpers.rb