Module: Waves::Resources::Mixin::ClassMethods

Included in:
Foundations::REST::Resource
Defined in:
lib/waves/resources/mixin.rb

Instance Method Summary collapse

Instance Method Details

#after(path = nil, options = {}, &block) ⇒ Object



51
52
53
# File 'lib/waves/resources/mixin.rb', line 51

def after( path = nil, options = {}, &block )
  on( :after, path, options, &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, options = {}, &block )
  on( :before, path, options, &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, options = nil, &block )
  if path.is_a? Hash
    generator = path.keys.first
    path = path.values.first
  end
  if options
    options[ :path ] = path
  else
    options = { :path => path }
  end
  options = @options.merge( options ) if @options
  matcher = Waves::Matchers::Resource.new( options )
  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

#pathsObject



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 ) ; @options = 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, options = {}, &block )
  before( path, options, &block )
  after( path, options, &block )
end