Sha256: ef5ed38538cab96fa713aa424a74e6aef93025ce5925ce28f3bd2487921044be

Contents?: true

Size: 841 Bytes

Versions: 59

Compression:

Stored size: 841 Bytes

Contents

require 'active_admin/resource'

module ActiveAdmin
  class Resource
    class BelongsTo

      class TargetNotFound < StandardError; end

      # The resource which initiated this relationship
      attr_reader :owner

      def initialize(owner_resource, target_name, options = {})
        @owner, @target_name = owner_resource, target_name
        @options = options
      end

      # Returns the target resource class or raises an exception if it doesn't exist
      def target
        namespace.resources.find_by_key(@target_name.to_s.camelize) or 
          raise TargetNotFound, "Could not find registered resource #{@target_name} in #{namespace.name} with #{namespace.resources.inspect}"
      end

      def namespace
        @owner.namespace
      end

      def optional?
        @options[:optional]
      end

    end
  end
end

Version data entries

59 entries across 59 versions & 3 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/resource/belongs_to.rb