Sha256: e9db994d36fa0b1ff0485b6040a4eb1cb6dfa0633f909c15f7b7af818bd919cc

Contents?: true

Size: 744 Bytes

Versions: 2

Compression:

Stored size: 744 Bytes

Contents

class KojacBaseSerializer < ActiveModel::Serializer

	self.root = false

	def initialize(object, options={})
		super(object,options)
	end

	SERIALIZABLE_TYPES = [NilClass,FalseClass,TrueClass,Fixnum,Bignum,String,Symbol,Hash,Array]

	def attributes
		attrs = nil
		source = if policy = Kojac::policy(scope,object)
			attrs = policy.permitted_attributes(:read).map(&:to_s)
			object.attributes
		elsif object.respond_to? :attributes
			object.attributes
		elsif object.is_a? Hash
			object
		end
		result = {}
		source.each do |k,v|
			k_s = k.to_s
			next if attrs && !attrs.include?(k_s)
			if SERIALIZABLE_TYPES.include? v.class
				result[k_s] = v
			else
				result[k_s] = KojacUtils.to_jsono(v,scope: scope)
			end
		end
		result
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kojac-0.13.0 app/serializers/kojac_base_serializer.rb
kojac-0.12.0 app/serializers/kojac_base_serializer.rb