Class: Lanes::API::RoutingBlock

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

Instance Method Summary collapse

Constructor Details

#initialize(ext_id) ⇒ RoutingBlock

Returns a new instance of RoutingBlock.



5
6
7
8
9
# File 'lib/lanes/api/routing.rb', line 5

def initialize(ext_id)
    Lanes::Extensions.for_identifier(ext_id) ||
        raise( "Unable to find extension '#{ext_id}' for screen group")
    @ext_id = ext_id
end

Instance Method Details

#resources(model, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/lanes/api/routing.rb', line 24

def resources(model, options = {})
    path = options[:path] || model.api_path
    controller = options[:controller] || Lanes::API::Controller
    parent_attribute = false
    if options[:under]
        parent_attribute = options[:parent_attribute] || options[:under].underscore.singularize+'_id'
    end

    prefix = parent_attribute ? parent_attribute + '/' : ''

    # index
    if controller.method_defined?(:perform_retrieval)
        get "#{prefix}#{path}/?:id?.json",
            &RequestWrapper.get(model, controller, parent_attribute)
    end

    # create
    if controller.method_defined?(:perform_creation)
        post "#{prefix}#{path}.json",
             &RequestWrapper.post(model, controller, parent_attribute)
    end

    unless options[:immutable]

        # update
        if controller.method_defined?(:perform_update)
            patch "#{prefix}#{path}/?:id?.json",
                  &RequestWrapper.update(model, controller, parent_attribute)
            put   "#{prefix}#{path}/?:id?.json",
                  &RequestWrapper.update(model, controller, parent_attribute)
        end

        if controller.method_defined?(:perform_destroy) and not options[:indestructible]
            # destroy
            delete "#{prefix}#{path}/?:id?.json",
                   &RequestWrapper.delete(model, controller, parent_attribute)
        end

    end

end

#root_view(view) ⇒ Object



11
12
13
14
15
16
# File 'lib/lanes/api/routing.rb', line 11

def root_view( view )
    API::Root.get Lanes.config.mounted_at + '?*' do
        pass unless request.accept? 'text/html'
        erb view
    end
end