Sha256: 1fefc0f7fcceb0da522a791d6f4977b25f81e8a9886a4bbdccd597b99bd8605d
Contents?: true
Size: 1.72 KB
Versions: 13
Compression:
Stored size: 1.72 KB
Contents
module InheritedResources #:nodoc: module PolymorphicHelpers #:nodoc: protected def parent_type @parent_type end def parent_class parent.class if @parent_type end def parent instance_variable_get("@#{@parent_type}") if @parent_type end private def parent? if resources_configuration[:polymorphic][:optional] parents_symbols.size > 1 || !@parent_type.nil? else true end end # Maps parents_symbols to build association chain. # # If the parents_symbols find :polymorphic, it goes through the # params keys to see which polymorphic parent matches the given params. # # When optional is given, it does not raise errors if the polymorphic # params are missing. # def symbols_for_chain polymorphic_config = resources_configuration[:polymorphic] parents_symbols.map do |symbol| if symbol == :polymorphic params_keys = params.keys key = polymorphic_config[:symbols].find do |poly| params_keys.include? resources_configuration[poly][:param].to_s end if key.nil? raise ScriptError, "Could not find param for polymorphic association. The request params keys are #{params.keys.inspect} and the polymorphic associations are #{polymorphic_symbols.inspect}." unless polymorphic_config[:optional] nil else @parent_type = key.to_sym end else symbol end end.compact end end end
Version data entries
13 entries across 13 versions & 1 rubygems