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
describe Tweet do | |
describe "basic fetching of tweets" do | |
describe "(search conditions)" do | |
attr_reader :new_search | |
before do | |
@new_search = mock(Twitter::Search, :null_object => true) | |
Twitter::Search.should_receive(:new).and_return(new_search) | |
end | |
after do | |
Tweet.fetch_new_tweets |
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
def interpret_time(time) | |
return nil if time.blank? | |
return time if time.kind_of?(Time) or time.kind_of?(Date) | |
named_time(time) || time_by_regex(time) || Time.parse(time) | |
end | |
def named_time(time) | |
case time.downcase | |
when "today" : Date.today | |
when "now" : Time.now |
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
# Depends on working pdftk, gm (GraphicsMagick), and pdftotext (Poppler) commands. | |
# Splits a pdf into batches of N pages, creates their thumbnails and icons, | |
# as specified in the Job options, gets the text for every page, and merges | |
# it all back into a tar archive for convenient download. | |
# | |
# See <tt>examples/process_pdfs_example.rb</tt> for more information. | |
class ProcessPdfs < CloudCrowd::Action | |
# Split up a large pdf into single-page pdfs. Batch them into 'batch_size' | |
# chunks for processing. The double pdftk shuffle fixes the document xrefs. |
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 GivesCreditToPreferredCustomers | |
LOOK_BACK_PERIOD = 3 | |
def self.for_large_orders(sales_amount, added_credit) | |
# the has_large_purchases scope now takes two arguments | |
preferred_customers = Customer.has_large_purchases(sales_amount, LOOK_BACK_PERIOD) | |
preferred_customers.each do |customer| | |
customer.add_credit added_credit | |
end | |
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
require 'active_model' | |
# Most of this is the basic boilerplate described in the docs for active_model/errors; ie, the bare minimum | |
# a class must have to use AM::Errors | |
class Post | |
extend ActiveModel::Naming | |
attr_reader :errors | |
attr_accessor :title, :author, :publication_date |
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 "active_model/lint" | |
require "test/unit/assertions" | |
shared_examples_for "ActiveModel" do | |
include ActiveModel::Lint::Tests | |
include Test::Unit::Assertions | |
before { @model = subject } | |
ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/).each do |test| |
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 WidgetShuffleMigration | |
def change | |
change_table :widgets do |t| | |
# used to store the result of a rand() function, which satisifies: 0 < rand() < 1 | |
t.float :shuffle_order, index: true | |
end | |
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
require 'charlatan' | |
# A simple pagination wrapper that implements the handful of | |
# methods that Kaminari wants for displaying pagination. | |
# | |
# Currently requires implementing a `window` function in the | |
# relation as well. `limit().offeset()` filters are what make | |
# up that method. | |
class DatasetPagination | |
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 'rom/memory' | |
class BlenderRelation < ROM::Relation[:memory] | |
repository :memory | |
register_as :blender | |
forward :join | |
end | |
class PostWithTagsMapper < ROM::Mapper |
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
#!/usr/bin/env ruby | |
require 'bundler/inline' | |
require 'json' | |
gemfile(:install) do | |
gem 'rom', '>= 2.0', github: 'rom-rb/rom', branch: 'master' | |
gem 'rom-http', github: 'rom-http-rb/rom-http', branch: 'master' | |
gem 'faraday' | |
end |
OlderNewer