Sha256: e1713183aa36994494c9dab76bc895ece500883017d9488edecec8f205239511

Contents?: true

Size: 801 Bytes

Versions: 12

Compression:

Stored size: 801 Bytes

Contents

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[@target_name.to_s.camelize] or 
          raise TargetNotFound, "Could not find registered resource #{@target_name} in #{namespace.name} with #{namespace.resources.keys.inspect}"
      end

      def namespace
        @owner.namespace
      end

      def optional?
        @options[:optional]
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 4 rubygems

Version Path
andrewroth_activeadmin-0.3.4 lib/active_admin/resource/belongs_to.rb
activeadmin-0.3.4 lib/active_admin/resource/belongs_to.rb
activeadmin-0.3.3 lib/active_admin/resource/belongs_to.rb
activeadmin-0.3.2 lib/active_admin/resource/belongs_to.rb
activeadmin-0.3.1 lib/active_admin/resource/belongs_to.rb
activeadmin-0.3.0 lib/active_admin/resource/belongs_to.rb
nsm-activeadmin-0.2.2 lib/active_admin/resource/belongs_to.rb
saulolso-activeadmin-0.2.2.1 lib/active_admin/resource/belongs_to.rb
saulolso-activeadmin-0.2.2 lib/active_admin/resource/belongs_to.rb
activeadmin-0.2.2 lib/active_admin/resource/belongs_to.rb
activeadmin-0.2.1 lib/active_admin/resource/belongs_to.rb
activeadmin-0.2.0 lib/active_admin/resource/belongs_to.rb