Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ gemspec
gem 'rubocop', '~> 1.21'
gem 'rubocop-performance'
gem 'byebug'
gem 'erubi'
gem 'oj'
gem 'rack'
gem 'pry', '~> 0.12.2'
gem 'rerun'
gem 'rspec'
Expand Down
118 changes: 0 additions & 118 deletions Gemfile.lock

This file was deleted.

2 changes: 2 additions & 0 deletions examples/playground/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ GEM
sequel (5.87.0)
bigdecimal
sqlite3 (2.8.1-x86_64-linux-gnu)
stimulux (1.0.0)
thin (1.8.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
Expand All @@ -118,6 +119,7 @@ DEPENDENCIES
rubocop
sequel
sqlite3
stimulux
thin

BUNDLED WITH
Expand Down
14 changes: 14 additions & 0 deletions examples/playground/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,16 @@ def call(_req)
end
end

module IncludeExample
def say_foo
'foo'
end
end

App =
Rackr.new(config).app do
include IncludeExample

get do |req|
req.session['visitas'] ||= 0

Expand All @@ -54,6 +62,12 @@ def call(_req)
render res:
end

get 'include_example' do
render (html_slice do
h1 say_foo
end)
end

get 'not_string_error' do
render 2
end
Expand Down
10 changes: 9 additions & 1 deletion lib/rackr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Rackr is a simple router for Rack.
class Rackr
VERSION = '0.0.69'
VERSION = '0.0.70'

class NotFound < StandardError; end

Expand All @@ -31,6 +31,14 @@ def initialize(config = {}, before: [], after: [])
@router = Router.new(config, before: before, after: after)
end

def include(mod)
self.class.include(mod)
end

def extend(mod)
self.class.extend(mod)
end

def app(&)
instance_eval(&)

Expand Down
13 changes: 8 additions & 5 deletions lib/rackr/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,19 @@ module Action

def self.included(base)
base.class_eval do
if self != Rackr
if self == Rackr
include HtmlSlice if Object.const_defined?('HtmlSlice')
include Stimulux if Object.const_defined?('Stimulux')
else
attr_reader :routes, :config, :deps, :db, :log, :cache

include Callbacks unless included_modules.include?(Rackr::Callback)
include Callbacks unless include?(Rackr::Callback)
end

include HtmlSlice if Object.const_defined?('HtmlSlice')
include Stimulux if Object.const_defined?('Stimulux')

def initialize(routes: nil, config: nil)
self.class.include(HtmlSlice) if Object.const_defined?('HtmlSlice')
self.class.include(Stimulux) if Object.const_defined?('Stimulux')

@routes = routes
@config = config
@deps = config&.dig(:deps)
Expand Down
2 changes: 2 additions & 0 deletions lib/spec/rackr/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ module ::HtmlSlice; end
require_relative action_file_path

action_class = Class.new { include Rackr::Action }
action_class.new # Create an instance to trigger the initialize method
expect(action_class.included_modules).to include(HtmlSlice)
end
end
Expand All @@ -630,6 +631,7 @@ module ::Stimulux; end
require_relative action_file_path

action_class = Class.new { include Rackr::Action }
action_class.new # Create an instance to trigger the initialize method
expect(action_class.included_modules).to include(Stimulux)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/spec/rackr/callback_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SomeClass3

RSpec.describe Rackr::Callback do
it 'includes http router action' do
expect(SomeClass3.included_modules.include?(Rackr::Action)).to be_truthy
expect(SomeClass3.include?(Rackr::Action)).to be_truthy
end

context 'not returning valid rack request' do
Expand Down
Binary file removed rackr-0.0.68.gem
Binary file not shown.
Binary file removed rackr-0.0.69.gem
Binary file not shown.
Binary file added rackr-0.0.70.gem
Binary file not shown.
4 changes: 1 addition & 3 deletions rackr.gemspec
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# frozen_string_literal: true

require_relative 'lib/rackr'

Gem::Specification.new do |s|
s.name = 'rackr'
s.version = Rackr::VERSION
s.version = File.read(File.expand_path("../lib/rackr.rb", __FILE__))[/VERSION = ['"](.+)['"]/, 1]
s.summary = 'Rack first web framework.'
s.description = 'Rack first web framework.'
s.authors = ['Henrique F. Teixeira']
Expand Down