Format:
#{attribute_name}_#{verb}_#{required}?_#{predicate}(options = {})
Format:
#{attribute_name}_#{verb}_#{required}?_#{predicate}(options = {})
| module Retriable | |
| # This will catch any exception and retry twice (three tries total): | |
| # with_retries { ... } | |
| # | |
| # This will catch any exception and retry four times (five tries total): | |
| # with_retries(:limit => 5) { ... } | |
| # | |
| # This will catch a specific exception and retry once (two tries total): | |
| # with_retries(Some::Error, :limit => 2) { ... } | |
| # |
| class QueueTimeMiddleware | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| if env['CONTENT_LENGTH'].to_i > 10000 | |
| env['HTTP_X_QUEUE_START'] = nil | |
| end |
| #!/usr/bin/env ruby | |
| X = 'hello' | |
| module A | |
| X = 'world' | |
| end | |
| module A::B | |
| def self.tst |
| # forgiveness is faster than permission | |
| private def catch_uniqueness_errors | |
| yield | |
| rescue ActiveRecord::RecordNotUnique => e | |
| field = e.cause.message.match(/index_([a-z_]*)_on_([a-z_]*)/)[2] | |
| raise unless field | |
| errors.add(field, :taken) | |
| end |
| /** | |
| * Mobiledoc 0.3.1 | |
| * https://github.com/bustlelabs/mobiledoc-kit/blob/master/MOBILEDOC.md#specification | |
| */ | |
| interface Mobiledoc { | |
| version: '0.3.1'; | |
| markups: Markup[]; | |
| atoms: Atom[]; | |
| cards: Card[]; |
| require 'keyword_struct' | |
| Mobiledoc = KeywordStruct.new(:version, :markups, :atoms, :cards, :sections) do | |
| Markup = Struct.new(:tag, :attrs) | |
| Atom = Struct.new(:name, :text, :payload) | |
| Card = Struct.new(:name, :payload) | |
| # Parses a serialized Mobiledoc into a collection of Ruby objects | |
| def self.parse(str) | |
| json = JSON.parse(str) |