Class: Toast::ConfigDSL::Association

Inherits:
Object
  • Object
show all
Includes:
Common, DefaultHandlers
Defined in:
lib/toast/config_dsl/association.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



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/toast/config_dsl/association.rb', line 61

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
19
20
# File 'lib/toast/config_dsl/association.rb', line 8

def via_get &block
  stack_push 'via_get' do
    @config_data.via_get =
      OpenStruct.new(permissions: [],
                     handler: (@config_data.singular ?
                                 singular_assoc_get_handler(@config_data.assoc_name) :
                                 plural_assoc_get_handler(@config_data.assoc_name)))

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


  end
end


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/toast/config_dsl/association.rb', line 37

def via_link &block
  stack_push 'via_link' do
    @config_data.via_link = OpenStruct.new(permissions: [],
                                           handler: (@config_data.singular ?
                                                       singular_assoc_link_handler(@config_data.assoc_name) :
                                                       plural_assoc_link_handler(@config_data.assoc_name)))

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

  end
end

#via_post(&block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/toast/config_dsl/association.rb', line 22

def via_post &block
  stack_push 'via_post' do
    if @config_data.singular
      raise_config_error "`via_post' is not allowed for singular associations"
    end

    @config_data.via_post = OpenStruct.new(permissions: [],
                                           handler: plural_assoc_post_handler(@config_data.assoc_name))

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


  end
end


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/toast/config_dsl/association.rb', line 49

def via_unlink &block
  stack_push 'via_unlink' do
    @config_data.via_unlink = OpenStruct.new(permissions: [],
                                             handler:  (@config_data.singular ?
                                                          singular_assoc_unlink_handler(@config_data.assoc_name) :
                                                          plural_assoc_unlink_handler(@config_data.assoc_name)))

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

  end
end