Skip to content

Instantly share code, notes, and snippets.

View lafave's full-sized avatar

Adam LaFave lafave

  • Dropbox
  • San Francisco
View GitHub Profile
@lafave
lafave / gist:f36cb68c35cce032758b
Created June 16, 2014 17:54
query_object_execute_concern.rb
# /app/models/concerns/query_object.rb
module QueryObject
extend ActiveSupport::Concern
module ClassMethods
# Convenience method to execute a query object.
def execute(*args)
new(*args).execute
end
end
# /app/queries/item_search_query.rb
class ItemSearchQuery
def self.execute(*args)
new(*args).execute
end
def initialize(query_string, opts = {})
@query_string = query_string
@opts = opts
end
@lafave
lafave / gist:6e3acbce1e1434fd0fe7
Created June 16, 2014 17:21
query_object_concern.rb
# /app/models/item.rb
class Item < ActiveRecord::Base
include ItemSearch
...
end
# /app/models/concerns/item_search.rb
module ItemSearch
extend ActiveSupport::Concern
# /app/models/item.rb
class Item < ActiveRecord::Base
...
def self.search(query_string, opts = {})
# Build the query
search_body = Jbuilder.encode do |json|
json.query do
json.filtered do
json.query do
premailer = Premailer.new "<html><body>some text</body></html>",
line_length: 10000, # Arbitrary length to prevent newlines from being added every 65 characters.
with_html_string: true # Let premailer know that this is a raw HTML string vs. an IO object or local path.
premailer.to_plain_text # => "some text"
class EmailProcessor
# @return [void]
def self.process(*args)
new(*args).process
end
# @param email [Gridler::Email]
#
# @return [EmailProcessor]