Sha256: d6fcf201e45efffb772d5985498be07ab605968f76b4498a1b327a6eff80be09

Contents?: true

Size: 954 Bytes

Versions: 14

Compression:

Stored size: 954 Bytes

Contents

require 'active_admin/resource'

module ActiveAdmin
  class Resource
    class BelongsTo

      class TargetNotFound < StandardError
        def initialize(key, namespace)
          super "Could not find #{key} in #{namespace.name} " +
                "with #{namespace.resources.map(&:resource_name)}"
        end
      end

      # The resource which initiated this relationship
      attr_reader :owner

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

      # Returns the target resource class or raises an exception if it doesn't exist
      def target
        key = @target_name.to_s.camelize
        namespace.resources[key] or raise TargetNotFound.new key, namespace
      end

      def namespace
        @owner.namespace
      end

      def optional?
        @options[:optional]
      end

      def required?
        !optional?
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
yousty-activeadmin-1.0.17.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.16.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.15.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.14.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.13.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.12.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.11.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.10.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.9.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.8.pre lib/active_admin/resource/belongs_to.rb
activeadmin-1.0.0.pre1 lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.7.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.6.pre lib/active_admin/resource/belongs_to.rb
yousty-activeadmin-1.0.5.pre lib/active_admin/resource/belongs_to.rb