Module: Toast::ConfigDSL::DefaultHandlers
- Included in:
- Association, Collection, Expose, Single
- Defined in:
- lib/toast/config_dsl/default_handlers.rb
Instance Method Summary collapse
- #canonical_delete_handler ⇒ Object
- #canonical_get_handler ⇒ Object
- #canonical_patch_handler ⇒ Object
- #collection_get_handler(model_class, coll_name) ⇒ Object
- #collection_post_handler(model_class) ⇒ Object
- #plural_assoc_get_handler(assoc_name) ⇒ Object
- #plural_assoc_link_handler(assoc_name) ⇒ Object
- #plural_assoc_post_handler(assoc_name) ⇒ Object
- #plural_assoc_unlink_handler(name) ⇒ Object
- #single_get_handler(model_class, single_name) ⇒ Object
- #singular_assoc_get_handler(assoc_name) ⇒ Object
- #singular_assoc_link_handler(assoc_name) ⇒ Object
- #singular_assoc_unlink_handler(assoc_name) ⇒ Object
Instance Method Details
#canonical_delete_handler ⇒ Object
50 51 52 53 54 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 50 def canonical_delete_handler lambda do |model, uri_params| model.destroy end end |
#canonical_get_handler ⇒ Object
26 27 28 29 30 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 26 def canonical_get_handler lambda do |model, uri_params| model end end |
#canonical_patch_handler ⇒ Object
32 33 34 35 36 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 32 def canonical_patch_handler lambda do |model, payload, uri_params| model.update payload end end |
#collection_get_handler(model_class, coll_name) ⇒ Object
20 21 22 23 24 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 20 def collection_get_handler model_class, coll_name lambda do |uri_params| model_class.send(coll_name) end end |
#collection_post_handler(model_class) ⇒ Object
38 39 40 41 42 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 38 def collection_post_handler model_class lambda do |payload, uri_params| model_class.create payload end end |
#plural_assoc_get_handler(assoc_name) ⇒ Object
2 3 4 5 6 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 2 def plural_assoc_get_handler assoc_name lambda do |source, uri_params| source.send(assoc_name) end end |
#plural_assoc_link_handler(assoc_name) ⇒ Object
63 64 65 66 67 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 63 def plural_assoc_link_handler assoc_name lambda do |source, target, uri_params| source.send(assoc_name) << target end end |
#plural_assoc_post_handler(assoc_name) ⇒ Object
44 45 46 47 48 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 44 def plural_assoc_post_handler assoc_name lambda do |source, payload, uri_params| source.send(assoc_name).create payload end end |
#plural_assoc_unlink_handler(name) ⇒ Object
78 79 80 81 82 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 78 def plural_assoc_unlink_handler name lambda do |source, target, uri_params| source.send(name).delete(target) end end |
#single_get_handler(model_class, single_name) ⇒ Object
14 15 16 17 18 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 14 def single_get_handler model_class, single_name lambda do |uri_params| model_class.send(single_name) end end |
#singular_assoc_get_handler(assoc_name) ⇒ Object
8 9 10 11 12 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 8 def singular_assoc_get_handler assoc_name lambda do |source, uri_params| source.send(assoc_name) end end |
#singular_assoc_link_handler(assoc_name) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 56 def singular_assoc_link_handler assoc_name lambda do |source, target, uri_params| source.send("#{assoc_name}=", target) source.save end end |
#singular_assoc_unlink_handler(assoc_name) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/toast/config_dsl/default_handlers.rb', line 69 def singular_assoc_unlink_handler assoc_name lambda do |source, target, uri_params| if source.send(assoc_name) == target source.send("#{assoc_name}=", nil) source.save end end end |