Class: Lanes::API::Handlers::Asset

Inherits:
Object
  • Object
show all
Defined in:
lib/lanes/api/handlers/asset.rb

Class Method Summary collapse

Class Method Details

.getterObject



28
29
30
31
32
33
34
# File 'lib/lanes/api/handlers/asset.rb', line 28

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

.saverObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lanes/api/handlers/asset.rb', line 5

def self.saver
    lambda do
        path = "#{params['extension_id']}/#{params['owner_type']}"
        model = path.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
                        owner.send("build_#{params['owner_association']}")
                    end

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

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