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 'equalizer' | |
| module Checkproc | |
| InvalidValueError = Class.new(StandardError) { include Equalizer.new(:message) } | |
| class Composite | |
| attr_reader :left | |
| attr_reader :right | |
| def initialize(left, right) |
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
| Calculating ------------------------------------- | |
| method 97.664k i/100ms | |
| proc 85.151k i/100ms | |
| ------------------------------------------------- | |
| method 2.611M (± 3.7%) i/s - 13.087M | |
| proc 1.910M (± 3.4%) i/s - 9.537M | |
| Comparison: | |
| method: 2611065.1 i/s | |
| proc: 1909549.3 i/s - 1.37x slower |
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 'transproc' | |
| include Transproc::Helper | |
| def source_fn(source) | |
| t(:add_keys, [:source]) >> t(:map_array, t(:map_value, :source, proc { source })) | |
| end | |
| fb_source = source_fn(:facebook) | |
| tw_source = source_fn(:twitter) |
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 'rom' | |
| require 'transproc' | |
| module Transformations | |
| extend Transproc::Functions | |
| def eval_keys(hash, param) | |
| hash.each_with_object(Hash[hash]) do |(key, value), copy| | |
| copy[key] = | |
| case value |
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 'rom' | |
| require 'byebug' | |
| rom = ROM.setup(:memory) do | |
| relation(:users) | |
| relation(:tasks) | |
| relation(:tags) | |
| commands(:users) do | |
| define(:create) do |
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 "rom/memory" | |
| memory_repo = ROM::Memory::Repository.new | |
| user_dataset = memory_repo.dataset(:users) | |
| class Users < ROM::Relation[:memory] | |
| end | |
| class UserMapper < ROM::Mapper | |
| model name: 'UserEntity' # ROM supports generating model classes |
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 'rom' | |
| require 'rom/support/options' | |
| require 'rom/support/data_proxy' | |
| class MyDataset | |
| include ROM::Options | |
| include ROM::DataProxy | |
| option :connection, reader: true |
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 'rom' | |
| Batman = Struct.new(:secret_name) | |
| Transproc.register(:to_batman, proc { |name| Batman.new(name) }) | |
| class GothamCityMapper < ROM::Mapper | |
| attribute :superhero, type: :batman | |
| 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
| require 'active_record' | |
| require 'hotch' | |
| ActiveRecord::Base.establish_connection('postgresql://localhost/rom') | |
| class User < ActiveRecord::Base | |
| end | |
| User.delete_all |
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 'rom' | |
| require 'rspec' | |
| module ROM | |
| class Relation | |
| class Composite | |
| attr_reader :left, :right | |
| def initialize(left, right) | |
| @left = left |