This file contains hidden or 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
# common validation style implemented on top of dry-validation | |
validates :title, length: { minimum: 20 } | |
# or use predicates | |
validates(:title).filled(min_size?: 20) | |
# or validate however you want | |
validates :title do |value| | |
# ... | |
end |
This file contains hidden or 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
# Demonstration of how state will be passed from the route context to presenter. | |
# Presentation will not occur in the routing context, so only what is exposed is available. | |
module Helpers | |
presentable :current_user, :current_resource | |
def current_user | |
@current_user ||= data.user.find(session[:user]) | |
end |
This file contains hidden or 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
AllCops: | |
Exclude: | |
- 'bin/**/*' | |
- 'vendor/**/*' | |
DisplayCopNames: true | |
BlockDelimiters: | |
EnforcedStyle: semantic | |
Lint/AssignmentInCondition: |
This file contains hidden or 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
AllCops: | |
Exclude: | |
- 'bin/**/*' | |
- 'vendor/**/*' | |
DisplayCopNames: true | |
BlockDelimiters: | |
EnforcedStyle: semantic | |
Lint/AssignmentInCondition: |
This file contains hidden or 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
module Pakyow | |
class App | |
load :resources, with: Loaders::Resource | |
end | |
module Loaders | |
class Resource < Base | |
location :resources | |
def initialize(filename, resource) |
This file contains hidden or 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
require "bundler/setup" | |
require "pakyow" | |
require "rack/handler/puma" | |
def run | |
if Process.respond_to?(:fork) | |
@pid = Process.fork do | |
require "./app/setup" | |
Pakyow::App.run(ENV['RACK_ENV']) |
This file contains hidden or 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
# add these to your Gemfile under the `test` group: | |
gem "factory_girl" | |
gem "database_cleaner" | |
# spec_helper.rb should look similar to: | |
require 'pakyow-test' | |
require 'factory_girl' | |
require 'database_cleaner' | |
require_relative '../app/setup' |
This file contains hidden or 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
# Comment with what benchmark you think would be faster, and why. | |
require "benchmark" | |
data = { | |
'foo' => 'bar' | |
} | |
count = 100_000_000 |
This file contains hidden or 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
require 'pakyow-core' | |
Pakyow::App.define do | |
routes do | |
default do | |
puts 'hello' | |
end | |
end | |
end.run |
This file contains hidden or 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
AllCops: | |
Exclude: | |
- 'bin/**/*' | |
- 'vendor/**/*' | |
DisplayCopNames: true | |
BlockDelimiters: | |
EnforcedStyle: semantic | |
Metrics/LineLength: |