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.



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
90
# File 'lib/generic/generic.rb', line 65

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



179
180
181
# File 'lib/generic/generic.rb', line 179

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

.before(&block) ⇒ Object

Before Proccess



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

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

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



123
124
125
126
127
# File 'lib/generic/generic.rb', line 123

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



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

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



130
131
132
133
134
135
136
137
# File 'lib/generic/generic.rb', line 130

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

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

Import



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

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

.library(*args, &block) ⇒ Object

System Helper



158
159
160
161
162
163
164
165
166
# File 'lib/generic/generic.rb', line 158

def library(*args, &block)
  if block_given?
    args << Module.new(&block)
  end

  args.each do |m|
    scope.send :include, m
  end
end

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



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

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



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

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



140
141
142
143
144
145
146
147
# File 'lib/generic/generic.rb', line 140

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



150
151
152
153
154
155
# File 'lib/generic/generic.rb', line 150

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



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

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

#settingsObject



97
98
99
# File 'lib/generic/generic.rb', line 97

def settings
  self.class.settings
end