Original author is rcknr. I manually transpiled to use JS classes
See here
Otherwise, put this gist into a file called map-label.js
and include with import MapLabel from './map-label'
. From there, follow the instructions outlined above.
<?php | |
class PostsController { | |
public function show($params) { // Note that you have to accept an argument here to get param information | |
$post = Post.find($params['id']); // This param comes from the identifier we set in the route. Note that the `Post.find` is a fictional method | |
include 'views/posts/show.php'; | |
} | |
public function index($params) { |
<?php | |
$router = new Router(); | |
// Traditional routes | |
$router->route('POST', '/posts', 'posts#create'); // This looks for PostsController with a method named `create` | |
$router->route('GET', '/posts', 'posts#index'); | |
$router->route('GET', '/posts/{:id}', 'posts#show'); // This will pass a param with a key of `id` and a value of whatever is in the URL | |
$router->route('PATCH', '/posts/{:id}', 'posts#update'); | |
$router->route('GET', '/me', 'users#show'); // It's worth noting that the lack of a trailing slash is important. `/me/` will not match `/me` and vice-versa |
class Post { // The name of this class doesn't matter, nor does the filepath | |
constructor() { | |
// Code related to this class' setup. Not required for Punchbox to run | |
} | |
controller() { | |
// Code within here will run on every action of the controller | |
} | |
index() { | |
// This code will run on the Posts#index action specifically | |
} |
# Drop into test_helper.rb or similar | |
def assert_differences(expression_array, by:, message: nil, &block) | |
expressions = Array(expression_array) | |
change_by = Array(by).map(&:to_i) | |
if expressions.size != change_by.size | |
raise ArgumentError, 'Each expression must have a corresponding value to change by' | |
end | |
exps = expressions.map.with_index do |e, i| |
assert_differences(['User.count', 'Post.count'], by: [-1, -5]) do | |
# Logic... | |
end | |
assert_differences('User.count', by: -1) do | |
# Logic... (although you should be using assert_difference in this case) | |
end | |
assert_differences(-> { User.count }, by: -1) do | |
# I can do lambdas too! |
assert_difference('User.count', -1) do | |
assert_difference('GoodbyeMailerJob.size', +1) do | |
assert_difference('Post.count', -5) do | |
# Logic... | |
end | |
end | |
end |
def assert_differences(expression_array, by:, message: nil, &block) | |
expressions = Array(expression_array) | |
change_by = Array(by).map(&:to_i) | |
if expressions.size != change_by.size | |
raise ArgumentError, 'Each expression must have a corresponding value to change by' | |
end | |
exps = expressions.map.with_index do |e, i| | |
callable = e.respond_to?(:call) ? e : lambda { eval(e, block.binding) } |
module HelperProxy | |
HELPER_DIRECTORY = Dir[Rails.root.join('app', 'helpers', '**', '*.rb')] | |
HELPER_DIRECTORY.each do |file| | |
include file.split(/\/helpers\/(.*?)\.rb/)[1].classify.safe_constantize | |
end | |
end |
pkill -USR1 puma-dev |