diff --git a/Gemfile b/Gemfile index d51bf32..4aa5ff6 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 34af704..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,118 +0,0 @@ -PATH - remote: . - specs: - rackr (0.0.69) - erubi (~> 1.12) - oj (~> 3.15) - rack (>= 2.0, < 4.0) - -GEM - remote: https://rubygems.org/ - specs: - ast (2.4.3) - bigdecimal (4.0.1) - byebug (12.0.0) - coderay (1.1.3) - diff-lcs (1.6.2) - erubi (1.13.1) - ffi (1.17.2) - ffi (1.17.2-aarch64-linux-gnu) - ffi (1.17.2-aarch64-linux-musl) - ffi (1.17.2-arm-linux-gnu) - ffi (1.17.2-arm-linux-musl) - ffi (1.17.2-arm64-darwin) - ffi (1.17.2-x86-linux-gnu) - ffi (1.17.2-x86-linux-musl) - ffi (1.17.2-x86_64-darwin) - ffi (1.17.2-x86_64-linux-gnu) - ffi (1.17.2-x86_64-linux-musl) - json (2.18.0) - language_server-protocol (3.17.0.5) - lint_roller (1.1.0) - listen (3.9.0) - rb-fsevent (~> 0.10, >= 0.10.3) - rb-inotify (~> 0.9, >= 0.9.10) - method_source (0.9.2) - oj (3.16.13) - bigdecimal (>= 3.0) - ostruct (>= 0.2) - ostruct (0.6.3) - parallel (1.27.0) - parser (3.3.10.0) - ast (~> 2.4.1) - racc - prism (1.7.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - racc (1.8.1) - rack (3.2.4) - rainbow (3.1.1) - rake (13.3.1) - rb-fsevent (0.11.2) - rb-inotify (0.11.1) - ffi (~> 1.0) - regexp_parser (2.11.3) - rerun (0.14.0) - listen (~> 3.0) - rspec (3.13.2) - rspec-core (~> 3.13.0) - rspec-expectations (~> 3.13.0) - rspec-mocks (~> 3.13.0) - rspec-core (3.13.6) - rspec-support (~> 3.13.0) - rspec-expectations (3.13.5) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-mocks (3.13.7) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.13.0) - rspec-support (3.13.6) - rubocop (1.82.0) - json (~> 2.3) - language_server-protocol (~> 3.17.0.2) - lint_roller (~> 1.1.0) - parallel (~> 1.10) - parser (>= 3.3.0.2) - rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 2.9.3, < 3.0) - rubocop-ast (>= 1.48.0, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.48.0) - parser (>= 3.3.7.2) - prism (~> 1.4) - rubocop-performance (1.26.1) - lint_roller (~> 1.1) - rubocop (>= 1.75.0, < 2.0) - rubocop-ast (>= 1.47.1, < 2.0) - ruby-progressbar (1.13.0) - unicode-display_width (3.2.0) - unicode-emoji (~> 4.1) - unicode-emoji (4.2.0) - -PLATFORMS - aarch64-linux-gnu - aarch64-linux-musl - arm-linux-gnu - arm-linux-musl - arm64-darwin - ruby - x86-linux-gnu - x86-linux-musl - x86_64-darwin - x86_64-linux-gnu - x86_64-linux-musl - -DEPENDENCIES - byebug - pry (~> 0.12.2) - rackr! - rake - rerun - rspec - rubocop (~> 1.21) - rubocop-performance - -BUNDLED WITH - 2.6.6 diff --git a/examples/playground/Gemfile.lock b/examples/playground/Gemfile.lock index 3233cd5..5cafa71 100644 --- a/examples/playground/Gemfile.lock +++ b/examples/playground/Gemfile.lock @@ -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) @@ -118,6 +119,7 @@ DEPENDENCIES rubocop sequel sqlite3 + stimulux thin BUNDLED WITH diff --git a/examples/playground/app.rb b/examples/playground/app.rb index 97cc872..213b3ac 100644 --- a/examples/playground/app.rb +++ b/examples/playground/app.rb @@ -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 @@ -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 diff --git a/lib/rackr.rb b/lib/rackr.rb index 01b9e0a..f08756a 100644 --- a/lib/rackr.rb +++ b/lib/rackr.rb @@ -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 @@ -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(&) diff --git a/lib/rackr/action.rb b/lib/rackr/action.rb index bd4af9d..69e893c 100644 --- a/lib/rackr/action.rb +++ b/lib/rackr/action.rb @@ -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) diff --git a/lib/spec/rackr/action_spec.rb b/lib/spec/rackr/action_spec.rb index 4428d61..f69e576 100644 --- a/lib/spec/rackr/action_spec.rb +++ b/lib/spec/rackr/action_spec.rb @@ -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 @@ -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 diff --git a/lib/spec/rackr/callback_spec.rb b/lib/spec/rackr/callback_spec.rb index 8f64f5a..48cac47 100644 --- a/lib/spec/rackr/callback_spec.rb +++ b/lib/spec/rackr/callback_spec.rb @@ -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 diff --git a/rackr-0.0.68.gem b/rackr-0.0.68.gem deleted file mode 100644 index e68a1f2..0000000 Binary files a/rackr-0.0.68.gem and /dev/null differ diff --git a/rackr-0.0.69.gem b/rackr-0.0.69.gem deleted file mode 100644 index 127bf75..0000000 Binary files a/rackr-0.0.69.gem and /dev/null differ diff --git a/rackr-0.0.70.gem b/rackr-0.0.70.gem new file mode 100644 index 0000000..74a14da Binary files /dev/null and b/rackr-0.0.70.gem differ diff --git a/rackr.gemspec b/rackr.gemspec index 3b49dfd..e8fd51b 100644 --- a/rackr.gemspec +++ b/rackr.gemspec @@ -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']