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
> be ruby coerce-speed.rb | |
Rehearsal ------------------------------------------------------- | |
Poro 0.020000 0.000000 0.020000 ( 0.025502) | |
MongoidDoc 0.460000 0.000000 0.460000 ( 0.464085) | |
VirtusModel 0.210000 0.010000 0.220000 ( 0.219621) | |
VirtusModelNoCoerce 0.060000 0.000000 0.060000 ( 0.062512) | |
---------------------------------------------- total: 0.760000sec | |
user system total real | |
Poro 0.010000 0.000000 0.010000 ( 0.004206) |
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
# frozen_string_literal: true | |
module Foo | |
# Simple presenter module | |
# | |
# Uses Charlatan to create an `Foo::Presenter` module for use in the app. | |
# This isn't *strictly* a presenter - it's somewhere between a presenter, | |
# proxy, and/or decorator. | |
# | |
# Including `Foo::Presenter.new(:presented_thing)` in a class will |
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
require "concord" | |
require "procto" | |
# Small wrapper module for domain services. | |
# | |
# Creates a service object with a ::call method that delegates to the instance | |
# method name given in the `call` option. Defaults to :call. (Procto) | |
# | |
# Provides initializer arguments, sets the ivars, and optional public reader | |
# methods for the attribute names passed in for `attrs`. (Concord) |
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
# Example: | |
# | |
# class EditForm < FormModel | |
# model :a | |
# | |
# attribute :title, String | |
# | |
# validates :title, presence: 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
class WithBlockVar | |
attr_accessor :z | |
def initialize(x, &blk) | |
@x = x | |
instance_eval(&blk) if block_given? | |
end | |
end | |
# Using block variable | |
a = WithBlockVar.new("A") do |
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
# An attempt to codify how we're using Service Objects now | |
# | |
# Most follow this pattern: | |
# | |
# class SomeService | |
# | |
# def self.call(a, b, &block) | |
# new(a, b).call(&block) | |
# 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
module Entity | |
include Virtus.module | |
attribute :id, Integer | |
def persisted? | |
!id.nil? | |
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
class SomeTypes | |
@all = [ | |
["TypeA", "Type A"], | |
["Type B", "Type B"], | |
] | |
Type = Struct.new(:type, :name, :slug, :sym) do | |
alias_method :to_ary, :to_a | |
# allows Type to be used for ifnone option in .find |
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
require "mechanize" | |
# we need some methods to clean this up so make it a class | |
class InspectionScraper | |
BASE_URL = "http://eats.washoecounty.us/" | |
FACILITY_COLS = ["link", "name", "score", "facility_type", "address", "inspection_date"] | |
RESULTS_TABLE_ID = "table#ctl00_ContentPlaceHolder1_grdHealth" |
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
require "virtus" | |
class Teacher | |
include Virtus::ValueObject | |
attribute :id, String | |
def self.inherited(descendant) | |
super |
NewerOlder