Module: Waves::Resources::Mixin::ClassMethods
- Included in:
- Foundations::REST::Resource
- Defined in:
- lib/waves/resources/mixin.rb
Instance Method Summary collapse
- #after(path = nil, options = {}, &block) ⇒ Object
- #always(&block) ⇒ Object
- #before(path = nil, options = {}, &block) ⇒ Object
- #handler(exception, &block) ⇒ Object
- #on(method, path = true, options = nil, &block) ⇒ Object
- #paths ⇒ Object
- #with(options) ⇒ Object
- #wrap(path = nil, options = {}, &block) ⇒ Object
Instance Method Details
#after(path = nil, options = {}, &block) ⇒ Object
51 52 53 |
# File 'lib/waves/resources/mixin.rb', line 51 def after( path = nil, = {}, &block ) on( :after, path, , &block ) end |
#always(&block) ⇒ Object
59 |
# File 'lib/waves/resources/mixin.rb', line 59 def always( &block ) ; define_method( :always, &block ) ; end |
#before(path = nil, options = {}, &block) ⇒ Object
48 49 50 |
# File 'lib/waves/resources/mixin.rb', line 48 def before( path = nil, = {}, &block ) on( :before, path, , &block ) end |
#handler(exception, &block) ⇒ Object
58 |
# File 'lib/waves/resources/mixin.rb', line 58 def handler( exception, &block ) ; functor( :handler, exception, &block ) ; end |
#on(method, path = true, options = nil, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/waves/resources/mixin.rb', line 23 def on( method, path = true, = nil, &block ) if path.is_a? Hash generator = path.keys.first path = path.values.first end if [ :path ] = path else = { :path => path } end = @options.merge( ) if @options matcher = Waves::Matchers::Resource.new( ) methods = case method when nil then nil when true then [ :post, :get, :put, :delete ] when Array then method else [ method ] end methods.each do | method | functor_with_self( method, matcher, &block ) end paths.module_eval { define_method( generator ) { | *args | generate( path, args ) } } if generator end |
#paths ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/waves/resources/mixin.rb', line 11 def paths unless @paths resource = self @paths = Class.new( superclass.respond_to?( :paths ) ? superclass.paths : Waves::Resources::Paths ) do @resource = resource def self.resource ; @resource ; end end else @paths end end |
#with(options) ⇒ Object
22 |
# File 'lib/waves/resources/mixin.rb', line 22 def with( ) ; @options = ; yield ; @options = nil ; end |
#wrap(path = nil, options = {}, &block) ⇒ Object
54 55 56 57 |
# File 'lib/waves/resources/mixin.rb', line 54 def wrap( path = nil, = {}, &block ) before( path, , &block ) after( path, , &block ) end |