lib/lifeboat.rb in lifeboat-0.2.5 vs lib/lifeboat.rb in lifeboat-0.3.0
- old
+ new
@@ -4,11 +4,10 @@
require 'yaml'
require 'fileutils'
require 'thread'
class AWS
-
# DUPLICATION IS RISING ON THE self.root METHOD
# MACHETE
def self.root
if Rails.version == "2.1.2"
YAML::load(IO.read(Rails.root + "/config/aws.yml"))
@@ -20,11 +19,10 @@
end
end
end
-
class Credentials
def initialize
# TRIED USING THE INITIALIZE FOR THOSE YAML LOADING DOWN THERE
# BUT IT WAS GIVING ME CRAP AND HAD TO DUPLICATE THE LINE
# MY GUEST IS THAT IT IS B/C THEY ARE CLASS METHODS
@@ -43,37 +41,50 @@
end
end
module LifeBoat
- def self.included(base)
- raise "Object Lacks Proper Callbacks" unless base.respond_to? :after_create
- base.class_eval do
- after_create :create_lifeboat
- after_destroy :destroy_lifeboat
- after_update :update_lifeboat
- end
- end
def self.read_queue(name)
#TODO EXTRAT OUT THE @CUE INTO HIGHER LEVEL
@cue = RightAws::SqsGen2.new(Credentials.key, Credentials.secret)
return @cue.queue(name).receive_messages
end
- def after_initialize
- @cue = RightAws::SqsGen2.new(Credentials.key, Credentials.secret)
+ module ActiveRecord
+ def has_lifeboat(options={})
+ include LifeBoat::Queues
+
+ if options[:format] == :xml
+ format = :to_xml
+ else
+ format = :to_json
+ end
+
+ [:create, :update, :destroy ].each do |action|
+ define_method(action.to_s + "_lifeboat") do
+ begin
+ @cue = RightAws::SqsGen2.new(Credentials.key, Credentials.secret)
+ queue_name = action.to_s+"_"+ self.class.to_s.downcase + "_" + RAILS_ENV
+ q = RightAws::SqsGen2::Queue.create(@cue, queue_name, true, 1000)
+ q.send_message(self.attributes.send format)
+ rescue RightAws::AwsError => error
+ puts error
+ end
+ end
+ end
+ end
end
- [:create, :update, :destroy ].each do |action|
- define_method(action.to_s + "_lifeboat") do
- begin
- queue_name = action.to_s+"_"+ self.class.to_s.downcase + "_" + RAILS_ENV
- q = RightAws::SqsGen2::Queue.create(@cue, queue_name, true)
- q.send_message(self.attributes.to_json)
- rescue RightAws::AwsError => e
- puts "LifeBoat RightAws::AwsError TIMEOUT"
- puts e
+ module Queues
+ def self.included(base)
+ raise "Object Lacks Proper Callbacks" unless base.respond_to? :after_create
+ base.class_eval do
+ after_create :create_lifeboat
+ after_destroy :destroy_lifeboat
+ after_update :update_lifeboat
end
end
end
end
+
+ActiveRecord::Base.extend LifeBoat::ActiveRecord