Class: Bebop::ResourceRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/bebop/ext.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_resources = [], before_all = [], after_all = []) ⇒ ResourceRouter

Returns a new instance of ResourceRouter.



40
41
42
43
44
# File 'lib/bebop/ext.rb', line 40

def initialize(parent_resources=[], before_all=[], after_all=[])
  @current_resource = parent_resources.pop
  @parent_resources = parent_resources
  @before, @after, @routes = before_all, after_all, []
end

Instance Attribute Details

#routesObject

Returns the value of attribute routes.



30
31
32
# File 'lib/bebop/ext.rb', line 30

def routes
  @routes
end

Instance Method Details

#after(*params, &block) ⇒ Object



98
99
100
# File 'lib/bebop/ext.rb', line 98

def after(*params, &block)
  add_filter(@after, params, block)
end

#before(*params, &block) ⇒ Object



94
95
96
# File 'lib/bebop/ext.rb', line 94

def before(*params, &block)
  add_filter(@before, params, block)
end

#create(options = {}, &block) ⇒ Object



70
71
72
# File 'lib/bebop/ext.rb', line 70

def create(options={}, &block)
  post '' , options.merge(:identifier => :create), &block
end

#delete(route, options = {}, &block) ⇒ Object



58
59
60
# File 'lib/bebop/ext.rb', line 58

def delete(route, options={}, &block)
  add_route(:delete, route, options, block)
end

#destroy(options = {}, &block) ⇒ Object



86
87
88
# File 'lib/bebop/ext.rb', line 86

def destroy(options={}, &block)
  delete resource_identifier, options.merge(:identifier => :destroy), &block
end

#edit(options = {}, &block) ⇒ Object



74
75
76
# File 'lib/bebop/ext.rb', line 74

def edit(options={}, &block)
  get append_token(resource_identifier, 'edit') , options.merge(:identifier => :edit), &block
end

#get(route, options = {}, &block) ⇒ Object



46
47
48
# File 'lib/bebop/ext.rb', line 46

def get(route, options={}, &block)
  add_route(:get, route, options, block)
end

#head(route, options = {}, &block) ⇒ Object



62
63
64
# File 'lib/bebop/ext.rb', line 62

def head(route, options={}, &block)
  add_route(:head,  route, options,  block)
end

#index(options = {}, &block) ⇒ Object



78
79
80
# File 'lib/bebop/ext.rb', line 78

def index(options={}, &block)
  get '', options.merge(:identifier => :index), &block
end

#loggerObject



32
33
34
# File 'lib/bebop/ext.rb', line 32

def logger
  @@logger ||= Logger.new(STDOUT)
end

#logger=(val) ⇒ Object



36
37
38
# File 'lib/bebop/ext.rb', line 36

def logger=(val)
  @@logger = val
end

#new(options = {}, &block) ⇒ Object



66
67
68
# File 'lib/bebop/ext.rb', line 66

def new(options={}, &block)
  get 'new', options.merge(:identifier => :new), &block
end

#post(route, options = {}, &block) ⇒ Object



54
55
56
# File 'lib/bebop/ext.rb', line 54

def post(route, options={}, &block)
  add_route(:post, route, options, block)
end


111
112
113
114
115
116
117
118
119
# File 'lib/bebop/ext.rb', line 111

def print
  #TODO 6! 6! Block parameters, Ah Ah Ah! -> probably need route objects
  @routes.each do |method, route, options, block, helper, identifier|
    logger.info "#{route}"
    logger.info "  method:     #{method.to_s.upcase}"
    logger.info "  helper:     #{helper}" if helper
    logger.info "  identifier: #{identifier} " if identifier
  end
end

#put(route, options = {}, &block) ⇒ Object



50
51
52
# File 'lib/bebop/ext.rb', line 50

def put(route, options={}, &block)
  add_route(:put, route, options, block)
end

#resource(name) {|router| ... } ⇒ Object

Yields:

  • (router)


102
103
104
105
106
107
108
109
# File 'lib/bebop/ext.rb', line 102

def resource(name, &block)
  before_filters = filters(@before, :all, name)
  after_filters = filters(@after, :all, name)

  router = self.class.new(all_resources + [name], before_filters, after_filters)
  yield(router)
  @routes += router.routes
end

#show(route = nil, options = {}, &block) ⇒ Object



82
83
84
# File 'lib/bebop/ext.rb', line 82

def show(route=nil, options={}, &block)
  get append_token(resource_identifier, (route || '').to_s), options.merge(:identifier => route || :show), &block
end

#update(options = {}, &block) ⇒ Object



90
91
92
# File 'lib/bebop/ext.rb', line 90

def update(options={}, &block)
  put resource_identifier, options.merge(:identifier => :update), &block
end