class GrapeTokenAuth::ResourceCreator
Public Instance Methods
create!()
click to toggle source
# File lib/grape_token_auth/resource/resource_creator.rb, line 4 def create! validate_scope! validate_params! return false unless errors.empty? create_resource! return false unless errors.empty? resource end
Private Instance Methods
create_resource!()
click to toggle source
# File lib/grape_token_auth/resource/resource_creator.rb, line 15 def create_resource! @resource = resource_class.create(permitted_params.merge(provider: 'email')) return if @resource.valid? pull_validation_messages end
permitted_attributes()
click to toggle source
# File lib/grape_token_auth/resource/resource_creator.rb, line 21 def permitted_attributes white_list = GrapeTokenAuth.configuration.param_white_list || {} other_attributes = white_list[scope] || [] [:email, :password, :password_confirmation] + other_attributes end
unpack_params()
click to toggle source
# File lib/grape_token_auth/resource/resource_creator.rb, line 34 def unpack_params [:email, :password_confirmation, :password] .each_with_object({}) do |key, unpacked| unpacked[key] = Utility.find_with_indifference(params, key) end end
validate_params!()
click to toggle source
# File lib/grape_token_auth/resource/resource_creator.rb, line 27 def validate_params! unpack_params.each do |label, value| errors << validation_message(label, value) end errors.compact! end
validation_message(label, value)
click to toggle source
# File lib/grape_token_auth/resource/resource_creator.rb, line 41 def validation_message(label, value) return "#{label} is required" unless value return "#{label} must be a string" unless value.is_a? String nil end