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 'rubygems' | |
require 'eventmachine' | |
class Handler | |
include EventMachine::Deferrable | |
def takes_long_time(seconds = 5) | |
sleep(seconds) | |
puts "Awoke after #{seconds} seconds." | |
succeed(seconds) |
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 empty hash does not result in creating a new instance of the type. | |
# Required because that's what we get back from the relation. | |
class OptionalCoercer | |
def initialize(type) | |
@type = type | |
end | |
def call(value) | |
return unless value | |
value.values.any? ? type.new(value) : nil |
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 'scrypt' | |
module Virtus | |
class Attribute | |
class Password < ::Virtus::Attribute | |
primitive SCrypt::Password | |
def coerce(value) | |
value ? SCrypt::Password.new(value) : nil | |
rescue SCrypt::Errors::InvalidHash |
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 'bundler' | |
require 'erb' | |
# Generates a Nix expression for bundler-managed dependencies. | |
module Bundix | |
class << self | |
def run(gemfile = './Gemfile', lockfile = 'Gemfile.lock') | |
gems = resolve_deps(gemfile, lockfile) | |
checksums = compute_checksums(gems) | |
write_expr(gems, checksums) |
NewerOlder