Class: Toast::ConfigDSL::Collection

Inherits:
Object
  • Object
show all
Includes:
Common, DefaultHandlers
Defined in:
lib/toast/config_dsl/collection.rb

Instance Method Summary collapse

Methods included from DefaultHandlers

#canonical_delete_handler, #canonical_get_handler, #canonical_patch_handler, #collection_get_handler, #collection_post_handler, #plural_assoc_get_handler, #plural_assoc_link_handler, #plural_assoc_post_handler, #plural_assoc_unlink_handler, #single_get_handler, #singular_assoc_get_handler, #singular_assoc_link_handler, #singular_assoc_unlink_handler

Methods included from Common

#check_symbol_list, #initialize, #method_missing, #raise_config_error, #stack_push

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Toast::ConfigDSL::Common

Instance Method Details

#max_window(size) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/toast/config_dsl/collection.rb', line 34

def max_window size
  stack_push 'max_window' do
    if size.is_a?(Integer) and size > 0
      @config_data.max_window = size
    elsif size == :unlimited
      @config_data.max_window = 10**6 # yes that's inifinity 
    else
      raise_config_error 'max_window must a positive integer or :unlimited'
    end
  end
end

#via_get(&block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/toast/config_dsl/collection.rb', line 8

def via_get &block
  stack_push 'via_get' do
    @config_data.via_get =
      OpenStruct.new(permissions: [],
                     handler: collection_get_handler(@config_data.base_model_class,
                                                     @config_data.collection_name))

    Toast::ConfigDSL::ViaVerb.new(@config_data.via_get).instance_eval &block

  end
end

#via_post(&block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/toast/config_dsl/collection.rb', line 20

def via_post &block
  stack_push 'via_post' do
    unless @config_data.collection_name == :all
      raise_config_error "POST is supported for the `all' collection only"
    end

    @config_data.via_post = OpenStruct.new(permissions: [],
                                           handler: collection_post_handler(@config_data.base_model_class))

    Toast::ConfigDSL::ViaVerb.new(@config_data.via_post).instance_eval &block

  end
end