diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..409c17f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,27 @@ +name: CI + +on: + push: + branches: + - main + pull_request: +jobs: + test: + strategy: + matrix: + ruby: [ '3.3', '3.2', '3.1', '3.0', '2.7', '2.6', '2.5', '2.4' ] + fail-fast: false + runs-on: ubuntu-latest + name: ${{ matrix.ruby }} + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rspec + + env: + BUNDLE_JOBS: 4 + BUNDLE_PATH: vendor/bundle + CI: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d35e07f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -dist: trusty -language: ruby -rvm: - - 2.5.1 - - 2.4.1 - - 2.3.1 - - jruby-9.1.2.0 -script: - - bundle exec rspec spec/ -sudo: false -cache: - - bundler diff --git a/Gemfile b/Gemfile index e18d817..51078ff 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,7 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec -gem 'rubocop', group: 'development', require: false + +group :development do + gem "standard", require: false +end diff --git a/certs/parndt.pem b/certs/parndt.pem index 4a8c05f..255a910 100644 --- a/certs/parndt.pem +++ b/certs/parndt.pem @@ -1,25 +1,27 @@ -----BEGIN CERTIFICATE----- -MIIEMjCCApqgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhnZW1z -L0RDPXAvREM9YXJuZHQvREM9aW8wHhcNMTgxMDI5MDk0MjQ5WhcNMTkxMDI5MDk0 -MjQ5WjAjMSEwHwYDVQQDDBhnZW1zL0RDPXAvREM9YXJuZHQvREM9aW8wggGiMA0G -CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQClF0/voptshDoTILFgUjvkViCOPe3W -uuDwfSep+gc5AI83MmrmonN3L/dwm60D3HhZ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A +cC5hcm5kdC5pbzAaBgNVHRIEEzARgQ9nZW1zQHAuYXJuZHQuaW8wDQYJKoZIhvcN +AQELBQADggGBAAw69VoNOTd5HQOQczs0zm+p5bZw3e+EFiDy/N9o8Lv5rHfyGhA5 +f+faBqfxQHDB3VSEFtCnoVFsCUaC1AdRzWztqS40x5GgQRwcM2llTwMYv5C++gC2 +xPchTvi5FgDI++a05isObUvtNZ/wrZYBhy75ofzGAAMfuB/+XzsGbsOxSwZVlCne +YLkPa26euounYtKRGLz+X9YD4vDHP5VwsrqsvACMwVGHv+MIM3TQ3TvVrQ7QR9Ov +yUmuDhnAXep8omj9HyiukfqIdTsIMZK8nMcJH4wXC7mjjOBoyRtMwsQIT8OpwSP9 +A7++64WBwTLbbGSCMCdw8X1kmmaZjaPrNkJ4wNaeJPZPPgDmL1XKJavQ8xZ/nwGF +VXf+6/IyX9OrQwL2uw0b+1NiR2gFpOLcOy2ixKdua13S9CWRRsR3VJve+PIyycC7 +aLV+FI9i9b1YUXG2gDKqLOkF/FNBWNckAmGj7kYkdLG76G5aRGP0HvfKbIiQ3HTC +jAtsfxiSgc0fAw== -----END CERTIFICATE----- diff --git a/decorators.gemspec b/decorators.gemspec index 5de1003..cf4d34d 100644 --- a/decorators.gemspec +++ b/decorators.gemspec @@ -1,16 +1,16 @@ Gem::Specification.new do |s| - s.platform = Gem::Platform::RUBY - s.name = %q{decorators} - s.version = %q{2.0.6} - s.description = %q{Manages the process of loading decorators into your Rails application.} - s.summary = %q{Rails decorators plugin.} - s.email = %q{gems@p.arndt.io} - s.homepage = %q{https://github.com/parndt/decorators} - s.authors = ["Philip Arndt"] - s.license = %q{MIT} - s.require_paths = %w(lib) + s.platform = Gem::Platform::RUBY + s.name = "decorators" + s.version = "2.0.6" + s.description = "Manages the process of loading decorators into your Rails application." + s.summary = "Rails decorators plugin." + s.email = "gems@p.arndt.io" + s.homepage = "https://github.com/parndt/decorators" + s.authors = ["Philip Arndt"] + s.license = "MIT" + s.require_paths = %w[lib] - s.files = %w[ + s.files = %w[ lib/decorators.rb lib/decorators/paths.rb lib/decorators/railtie.rb @@ -18,11 +18,11 @@ Gem::Specification.new do |s| readme.md ] - s.add_dependency "railties", ">= 4.0.0", "< 7.2" + s.add_dependency "railties", ">= 4.0.0", "< 7.2" s.add_development_dependency "rspec", "~> 3.5", ">= 3.5.0" - s.cert_chain = ["certs/parndt.pem"] - if $0 =~ /gem\z/ && ARGV.include?("build") && ARGV.include?(__FILE__) + s.cert_chain = ["certs/parndt.pem"] + if $0.end_with?("gem") && ARGV.include?("build") && ARGV.include?(__FILE__) s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") end end diff --git a/lib/decorators.rb b/lib/decorators.rb index f898c1e..d4f5c1c 100644 --- a/lib/decorators.rb +++ b/lib/decorators.rb @@ -1,5 +1,5 @@ module Decorators - require 'decorators/paths' + require "decorators/paths" class << self def load!(cache_classes) @@ -23,12 +23,13 @@ def register!(*paths_to_register) end protected + def paths @paths ||= Paths.new end def apply_decorators_pattern_to_path(path) - path.join *pattern + path.join(*pattern) end def find_decorators_in_path(path) @@ -36,10 +37,9 @@ def find_decorators_in_path(path) end def pattern - ['app', 'decorators', '*', '**', '*_decorator.rb'] + ["app", "decorators", "*", "**", "*_decorator.rb"] end end - end -require 'decorators/railtie' +require "decorators/railtie" diff --git a/lib/decorators/paths.rb b/lib/decorators/paths.rb index f1044de..b906f88 100644 --- a/lib/decorators/paths.rb +++ b/lib/decorators/paths.rb @@ -1,9 +1,9 @@ -require 'pathname' +require "pathname" module Decorators class Paths - attr_reader :registered + def initialize(*args) @registered = Array.new(*args) end @@ -11,6 +11,5 @@ def initialize(*args) def register!(path) @registered << Pathname.new(path) end - end end diff --git a/lib/decorators/railtie.rb b/lib/decorators/railtie.rb index f45c4ea..0cb402a 100644 --- a/lib/decorators/railtie.rb +++ b/lib/decorators/railtie.rb @@ -1,8 +1,7 @@ -require 'rails' +require "rails" module Decorators class Railtie < Rails::Railtie - config.before_initialize do |app| loader = proc { Decorators.load!(app.config.cache_classes) } @@ -12,6 +11,5 @@ class Railtie < Rails::Railtie app.config.to_prepare(&loader) end end - end end diff --git a/spec/decorators/path_spec.rb b/spec/decorators/path_spec.rb index 70095cf..86b77b4 100644 --- a/spec/decorators/path_spec.rb +++ b/spec/decorators/path_spec.rb @@ -1,27 +1,27 @@ -require 'spec_helper' +require "spec_helper" describe Decorators::Paths do context "initialized without arguments" do - let(:paths) {Decorators::Paths.new} + let(:paths) { Decorators::Paths.new } - it 'initialize empty array' do + it "initialize empty array" do expect(paths.registered).to eq([]) end - it 'adds path to registered paths' do + it "adds path to registered paths" do paths.register! "mypath" expect(paths.registered).to eq([Pathname.new("mypath")]) end end context "initialized with arguments" do - let(:paths) {Decorators::Paths.new([Pathname("initpath")])} + let(:paths) { Decorators::Paths.new([Pathname("initpath")]) } - it 'initialize array with argument path' do + it "initialize array with argument path" do expect(paths.registered).to eq([Pathname.new("initpath")]) end - it 'adds path to registered paths' do + it "adds path to registered paths" do paths.register! "mypath" expect(paths.registered.count).to eq(2) expect(paths.registered.last).to eq(Pathname.new("mypath")) diff --git a/spec/decorators_spec.rb b/spec/decorators_spec.rb index 788b0a8..bfb151c 100644 --- a/spec/decorators_spec.rb +++ b/spec/decorators_spec.rb @@ -1,20 +1,20 @@ -require 'spec_helper' -require_relative 'support/decorate_me.rb' +require "spec_helper" +require_relative "support/decorate_me" describe Decorators do before do - Decorators.register! File.expand_path('../support', __FILE__) + Decorators.register! File.expand_path("../support", __FILE__) Decorators.load! true end let(:decorated_class) { DecorateMe.new } - it 'register decorators' do + it "register decorators" do decorators = [ - decorator_path('decorate_me_decorator'), - decorator_path('another_decorator') + decorator_path("decorate_me_decorator"), + decorator_path("another_decorator") ] bad_decorators = [ - decorator_path('../do_not_load_this_decorator') + decorator_path("../do_not_load_this_decorator") ] decorators.each do |decorator| expect(Decorators.decorators).to include(decorator) @@ -26,12 +26,11 @@ end end - it 'decorates class with same file name' do + it "decorates class with same file name" do expect(decorated_class.kiwi).to eq("parndt") end - it 'decorates class with different file name' do + it "decorates class with different file name" do expect(decorated_class.am_i_decorated?).to eq(true) end end - diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0418ea5..4cfbf0d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,7 @@ config.run_all_when_everything_filtered = true config.filter_run :focus - config.order = 'random' + config.order = "random" end def decorator_path(name) @@ -13,10 +13,9 @@ def decorator_path(name) unless Kernel.respond_to?(:require_relative) module Kernel def require_relative(path) - require File.join(File.dirname(caller[0]), path.to_str) + require File.join(File.dirname(caller(1..1).first), path.to_str) end end end -require_relative '../lib/decorators' - +require_relative "../lib/decorators"