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
=begin | |
@author Chris Corbyn | |
@license None, use at your own risk | |
=end | |
module DataMapper | |
class Property | |
# Adds support for a sequences table to DataMapper, via a Sequence property type. | |
# | |
# class Person |
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
class Time | |
class << self | |
attr_accessor :mock_time | |
def now_with_mock_time | |
@mock_time || now_without_mock_time | |
end | |
alias_method_chain :now, :mock_time | |
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
class Example | |
include DataMapper::Resource | |
property :id, Serial | |
property :ip_address, IPAddressInteger | |
end | |
example = Example.new | |
example.ip_address = "10.48.1.1" |
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
# This is used temporarily, until serialization to :raw is done in dm-serializer | |
module DataMapper | |
module Rest | |
class CustomJsonFormat < DataMapperRest::Format::Json | |
def string_representation(resource) | |
model = resource.model | |
hash = {} | |
hash = model.properties.reduce(hash) do |h, property| | |
h.merge(property.field.to_sym => property.dump(property.get(resource))) |
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
ico_file = "some-file.ico" | |
png_file = "output.png" | |
Devil.load(ico_file) do |img| | |
img.resize(16, 16).save(png_file) | |
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
module Commerce | |
class Refund | |
include DataMapper::Resource | |
include Defaults | |
PENDING = 'pending' | |
SUCCESSFUL = 'successful' | |
DECLINED = 'declined' | |
ERROR = 'error' | |
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
module VerboseJob | |
module ClassMethods | |
def wrap_perform! | |
class << self | |
def perform_with_verbose(*args) | |
JobLogger.verbose { perform_without_verbose(*args) } | |
end | |
alias_method_chain :perform, :verbose \ | |
unless instance_method(:perform) == instance_method(:perform_with_verbose) |
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
# Resque job to do the true outbound sending | |
class DeliverEmailJob | |
include ProjectName::Job::Logging | |
@queue = :mail_queue | |
def self.perform(args) | |
message = QueuedEmail.get!(args["message_id"]) | |
logger.info("Delivering (%s) to %s" % [message.subject, message.formatted_recipient]) |
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 'spec_helper' | |
class AbstractStoreSubclass < ActionDispatch::Session::AbstractStore | |
def get_session(env, sid) | |
[sid || generate_sid, nil] | |
end | |
def set_session(env, sid, data, options) | |
end |
OlderNewer