Class: Generic::Base

Inherits:
Object
  • Object
show all
Includes:
Genericer::General
Defined in:
lib/generic/generic.rb

Direct Known Subclasses

Boot

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Genericer::General

included

Constructor Details

#initialize(app = nil) ⇒ Base

Returns a new instance of Base.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/generic/generic.rb', line 64

def initialize(app=nil)
  # Rack Builder
  builder = Rack::Builder.new

  #Register Importing Classes
  self.class.impt.each do |im, args, block|
    builder.use(im, *args, &block)
  end

  # Register group nested
  self.class.routes.each do |url, a_class|
    builder.map(url) do
      use a_class
    end
  end

  builder.run Generic::Routing.new({
                                       :scope => self.class.scope,
                                       :rd => self.class.rd,
                                       :before_actions => self.class.before_actions,
                                       :after_actions => self.class.after_actions,
                                       :fail => app
                                   })

  @app = builder.to_app
end

Class Method Details

.after(&block) ⇒ Object

After Proccess



173
174
175
# File 'lib/generic/generic.rb', line 173

def after(&block)
  after_actions << Proc.new(&block)
end

.before(&block) ⇒ Object

Before Proccess



168
169
170
# File 'lib/generic/generic.rb', line 168

def before(&block)
  before_actions << Proc.new(&block)
end

.delete(path, options = {}, &block) ⇒ Object



118
119
120
121
122
# File 'lib/generic/generic.rb', line 118

def delete(path, options={}, &block)
  options[:constraints] = guard.merge(options[:constraints] || {})
  options[:constraints].merge!(:request_method => "DELETE")
  define_route(path, options, &block)
end

.get(path, options = {}, &block) ⇒ Object

Methods



100
101
102
103
104
# File 'lib/generic/generic.rb', line 100

def get(path, options={}, &block)
  options[:constraints] = guard.merge(options[:constraints] || {})
  options[:constraints].merge!(:request_method => "GET")
  define_route(path, options, &block)
end

.group(url, app = nil, &block) ⇒ Object

Group Route



125
126
127
128
129
130
131
132
# File 'lib/generic/generic.rb', line 125

def group(url, app=nil, &block)
  scope = self.scope
  app = Class.new(self.superclass) do
    self.scope = scope
    class_eval(&block)
  end
  routes[url] = app
end

.helpers(*args, &block) ⇒ Object

System Helper



153
154
155
156
157
158
159
160
# File 'lib/generic/generic.rb', line 153

def helpers(*args, &block)
  if block_given?
    args << Module.new(&block)
  end
  args.each do |m|
    scope.send :include, m
  end
end

.import(cls, *args, &block) ⇒ Object

Import



163
164
165
# File 'lib/generic/generic.rb', line 163

def import(cls, *args, &block)
  impt << [cls, args, block]
end

.post(path, options = {}, &block) ⇒ Object



106
107
108
109
110
# File 'lib/generic/generic.rb', line 106

def post(path, options={}, &block)
  options[:constraints] = guard.merge(options[:constraints] || {})
  options[:constraints].merge!(:request_method => "POST")
  define_route(path, options, &block)
end

.put(path, options = {}, &block) ⇒ Object



112
113
114
115
116
# File 'lib/generic/generic.rb', line 112

def put(path, options={}, &block)
  options[:constraints] = guard.merge(options[:constraints] || {})
  options[:constraints].merge!(:request_method => "PUT")
  define_route(path, options, &block)
end

.register(*extensions) ⇒ Object

Register Extension



135
136
137
138
139
140
141
142
# File 'lib/generic/generic.rb', line 135

def register(*extensions)
  extensions.each do |ext|
    extend ext
    if ext.check(self)
      ext.respond_to?(:registered)
    end
  end
end

.set_guard(args, &block) ⇒ Object

Set Guard



145
146
147
148
149
150
# File 'lib/generic/generic.rb', line 145

def set_guard(args, &block)
  current = self.guard.dup
  self.guard = args
  instance_eval(&block)
  self.guard = current
end

Instance Method Details

#call(env) ⇒ Object



92
93
94
# File 'lib/generic/generic.rb', line 92

def call(env)
  @app.call(env)
end