Sha256: 920300ef95600f10c1ed6b55203e31275cb2bf1374b83bd0fa7501a76e6f792a

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

module Lanes::API::Handlers

    class Asset

        def self.saver
            lambda do
                model = params['owner_type'].underscore.camelize.constantize

                authentication = Lanes::API::AuthenticationProvider.new(request)
                authentication.wrap_model_access(model, self) do
                    owner = model.find(params['owner_id'])
                    asset = if params['id']
                                ::Lanes::Asset.find(params['id'])
                            else
                                assoc = owner.class.reflections[
                                    params['owner_association']
                                ]
                                if assoc.collection?
                                    owner.send(params['owner_association']).build
                                else
                                    owner.send("build_#{params['owner_association']}")
                                end
                            end

                    asset.update(file: params['file'])

                    json_reply std_api_reply asset.new_record? ? :update : :create,
                                             asset,
                                             success: asset.save
                end
            end
        end

        def self.getter
            root = Lanes::Extensions.controlling.root_path.join('public', 'files')
            lambda do
                send_file(root.join( params['splat'].first ).to_s)
            end
        end
    end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lanes-0.8.3 lib/lanes/api/handlers/asset.rb
lanes-0.8.2 lib/lanes/api/handlers/asset.rb
lanes-0.8.1 lib/lanes/api/handlers/asset.rb
lanes-0.8.0 lib/lanes/api/handlers/asset.rb