-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move core extensions to new Foundation gem…more to follow!
- Loading branch information
1 parent
3ab6549
commit bef4af8
Showing
19 changed files
with
257 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
bridgetown-core/lib/bridgetown-core/core_ext/questionable_string.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
inherit_from: ../.rubocop.yml | ||
|
||
AllCops: | ||
Exclude: | ||
- "*.gemspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/gem_tasks" | ||
|
||
task spec: :test | ||
require "rake/testtask" | ||
Rake::TestTask.new(:test) do |test| | ||
test.libs << "lib" << "test" | ||
test.pattern = "test/**/test_*.rb" | ||
test.verbose = true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "lib/bridgetown/foundation/version" | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "bridgetown-foundation" | ||
spec.version = Bridgetown::Foundation::VERSION | ||
spec.author = "Bridgetown Team" | ||
spec.email = "[email protected]" | ||
spec.summary = "Ruby language extensions and other utilities useful for the Bridgetown ecosystem" | ||
spec.homepage = "https://github.com/bridgetownrb/bridgetown/tree/main/bridgetown-foundation" | ||
spec.license = "MIT" | ||
spec.required_ruby_version = ">= 3.1" | ||
|
||
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script)/!) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.metadata = { | ||
"source_code_uri" => "https://github.com/bridgetownrb/bridgetown", | ||
"bug_tracker_uri" => "https://github.com/bridgetownrb/bridgetown/issues", | ||
"changelog_uri" => "https://github.com/bridgetownrb/bridgetown/releases", | ||
"homepage_uri" => spec.homepage, | ||
"rubygems_mfa_required" => "true", | ||
} | ||
|
||
spec.add_dependency("zeitwerk", "~> 2.5") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bridgetown/foundation/version" | ||
require "zeitwerk" | ||
|
||
class Module | ||
# Due to Active Support incompatibility, we can't extend Gem::Deprecate directly in `Object` | ||
# So we're pulling this in as `gem_deprecate` from `deprecate`: | ||
# https://github.com/rubygems/rubygems/blob/v3.5.9/lib/rubygems/deprecate.rb | ||
# | ||
# Pass in the deprecated method name, the new method name, and the year & month it'll be removed | ||
# | ||
# @param name [Symbol] e.g. `:howdy` | ||
# @param repl [Symbol] e.g. `:hello` | ||
# @param year [Integer] e.g. `2025` | ||
# @param month [Integer] e.g. `1` for January | ||
def gem_deprecate(name, repl, year, month) | ||
# rubocop:disable Style/FormatStringToken | ||
class_eval do | ||
old = "_deprecated_#{name}" | ||
alias_method old, name | ||
define_method name do |*args, &block| | ||
klass = is_a? Module | ||
target = klass ? "#{self}." : "#{self.class}#" | ||
msg = [ | ||
"NOTE: #{target}#{name} is deprecated", | ||
repl == :none ? " with no replacement" : "; use #{repl} instead", | ||
format(". It will be removed on or after %4d-%02d.", year, month), | ||
"\n#{target}#{name} called from #{Gem.location_of_caller.join(":")}", | ||
] | ||
warn "#{msg.join}." unless Gem::Deprecate.skip | ||
send old, *args, &block | ||
end | ||
end | ||
# rubocop:enable Style/FormatStringToken | ||
end | ||
end | ||
|
||
Zeitwerk.with_loader do |l| | ||
l.push_dir "#{__dir__}/bridgetown/foundation", namespace: Bridgetown::Foundation | ||
l.ignore "#{__dir__}/bridgetown/foundation/version.rb" | ||
#l.ignore "#{__dir__}/bridgetown/foundation/core_ext/string.rb" | ||
l.setup | ||
l.eager_load | ||
end |
2 changes: 1 addition & 1 deletion
2
...ore/lib/bridgetown-core/core_ext/class.rb → ...b/bridgetown/foundation/core_ext/class.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 25 additions & 9 deletions
34
...re/lib/bridgetown-core/core_ext/object.rb → .../bridgetown/foundation/core_ext/object.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
bridgetown-foundation/lib/bridgetown/foundation/questionable_string.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bridgetown::Foundation | ||
class QuestionableString < ::String | ||
def method_missing(method_name, *args) | ||
value = method_name.to_s | ||
if value.end_with?("?") | ||
value.chop! | ||
return self == value | ||
end | ||
|
||
super | ||
end | ||
|
||
def respond_to_missing?(method_name, include_private = false) | ||
method_name.end_with?("?") || super | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bridgetown | ||
module Foundation | ||
# TODO: should we define versions here now and pull it within Core? | ||
VERSION = "1.3.4" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
set -ex | ||
|
||
script/fmt | ||
script/test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "Rubocop $(bundle exec rubocop --version)" | ||
bundle exec rubocop -D $@ | ||
success=$? | ||
if ((success != 0)); then | ||
echo -e "\nTry running \`script/fmt -a\` to automatically fix errors" | ||
fi | ||
exit $success |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Usage: | ||
# script/test <test_file> | ||
# script/test | ||
|
||
if [ -d test/dest ] | ||
then rm -r test/dest | ||
fi | ||
|
||
testopts="--profile" | ||
|
||
if [[ $# -lt 1 ]] | ||
then | ||
set -x | ||
time ruby -S bundle exec \ | ||
rake TESTOPTS=$testopts test | ||
else | ||
set -x | ||
time ruby -S bundle exec ruby -I test \ | ||
"$@" $testops | ||
fi |
Oops, something went wrong.