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



34
35
36
37
38
39
# File 'lib/lanes/api/handlers/asset.rb', line 34

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
27
28
29
30
31
32
# File 'lib/lanes/api/handlers/asset.rb', line 5

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