lifeboat 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.3.0
data/lib/lifeboat.rb CHANGED
@@ -6,7 +6,6 @@ require 'fileutils'
6
6
  require 'thread'
7
7
 
8
8
  class AWS
9
-
10
9
  # DUPLICATION IS RISING ON THE self.root METHOD
11
10
  # MACHETE
12
11
  def self.root
@@ -22,7 +21,6 @@ class AWS
22
21
  end
23
22
 
24
23
 
25
-
26
24
  class Credentials
27
25
  def initialize
28
26
  # TRIED USING THE INITIALIZE FOR THOSE YAML LOADING DOWN THERE
@@ -45,14 +43,6 @@ end
45
43
 
46
44
 
47
45
  module LifeBoat
48
- def self.included(base)
49
- raise "Object Lacks Proper Callbacks" unless base.respond_to? :after_create
50
- base.class_eval do
51
- after_create :create_lifeboat
52
- after_destroy :destroy_lifeboat
53
- after_update :update_lifeboat
54
- end
55
- end
56
46
 
57
47
  def self.read_queue(name)
58
48
  #TODO EXTRAT OUT THE @CUE INTO HIGHER LEVEL
@@ -60,20 +50,41 @@ module LifeBoat
60
50
  return @cue.queue(name).receive_messages
61
51
  end
62
52
 
63
- def after_initialize
64
- @cue = RightAws::SqsGen2.new(Credentials.key, Credentials.secret)
53
+ module ActiveRecord
54
+ def has_lifeboat(options={})
55
+ include LifeBoat::Queues
56
+
57
+ if options[:format] == :xml
58
+ format = :to_xml
59
+ else
60
+ format = :to_json
61
+ end
62
+
63
+ [:create, :update, :destroy ].each do |action|
64
+ define_method(action.to_s + "_lifeboat") do
65
+ begin
66
+ @cue = RightAws::SqsGen2.new(Credentials.key, Credentials.secret)
67
+ queue_name = action.to_s+"_"+ self.class.to_s.downcase + "_" + RAILS_ENV
68
+ q = RightAws::SqsGen2::Queue.create(@cue, queue_name, true, 1000)
69
+ q.send_message(self.attributes.send format)
70
+ rescue RightAws::AwsError => error
71
+ puts error
72
+ end
73
+ end
74
+ end
75
+ end
65
76
  end
66
77
 
67
- [:create, :update, :destroy ].each do |action|
68
- define_method(action.to_s + "_lifeboat") do
69
- begin
70
- queue_name = action.to_s+"_"+ self.class.to_s.downcase + "_" + RAILS_ENV
71
- q = RightAws::SqsGen2::Queue.create(@cue, queue_name, true)
72
- q.send_message(self.attributes.to_json)
73
- rescue RightAws::AwsError => e
74
- puts "LifeBoat RightAws::AwsError TIMEOUT"
75
- puts e
78
+ module Queues
79
+ def self.included(base)
80
+ raise "Object Lacks Proper Callbacks" unless base.respond_to? :after_create
81
+ base.class_eval do
82
+ after_create :create_lifeboat
83
+ after_destroy :destroy_lifeboat
84
+ after_update :update_lifeboat
76
85
  end
77
86
  end
78
87
  end
79
88
  end
89
+
90
+ ActiveRecord::Base.extend LifeBoat::ActiveRecord
data/lifeboat.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lifeboat}
8
- s.version = "0.2.5"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ivan Acosta-Rubio"]
@@ -11,7 +11,6 @@ ActiveRecord::Base.establish_connection(config['test'])
11
11
 
12
12
  def rebuild_model options = {}
13
13
  # ActiveRecord::Base.connection.create_database('lifeboat_test')
14
-
15
14
  ActiveRecord::Base.connection.create_table :fake_models, :force => true do |table|
16
15
  table.column :name, :string
17
16
  table.column :phone, :string
@@ -20,18 +19,27 @@ def rebuild_model options = {}
20
19
  ActiveRecord::Base.connection.create_table :fakes, :force => true do |table|
21
20
  table.column :name, :string
22
21
  end
22
+ ActiveRecord::Base.connection.create_table :xml_records, :force => true do |table|
23
+ table.column :name, :string
24
+ end
25
+
23
26
  end
24
27
 
25
28
  rebuild_model
26
29
 
27
30
  class FakeModel < ActiveRecord::Base
28
31
  attr_accessor :name, :email, :phone
29
- include LifeBoat
32
+ has_lifeboat
30
33
  end
31
34
 
32
35
  class Fake < ActiveRecord::Base
33
36
  attr_accessor :name
34
- include LifeBoat
37
+ has_lifeboat
38
+ end
39
+
40
+ class XMLRecord < ActiveRecord::Base
41
+ attr_accessor :name
42
+ has_lifeboat :format => :xml
35
43
  end
36
44
 
37
45
  RAILS_ENV = "test"
@@ -57,7 +65,7 @@ end
57
65
 
58
66
  describe "An simple object " do
59
67
  it "raises for not having callbacks" do
60
- lambda{ class BadModel ; include LifeBoat ; end }.should raise_error
68
+ lambda{ class BadModel ; has_lifeboat ; end }.should raise_error
61
69
  end
62
70
  end
63
71
 
@@ -110,7 +118,7 @@ describe LifeBoat do
110
118
  q[0].body.should == f.attributes.to_json
111
119
  end
112
120
 
113
- it "deletes SQS queue when parent is deleted" do
121
+ it "creates a destroy SQS queue when parent is destroyed" do
114
122
  f = Fake.create(:name => "updated")
115
123
  f.destroy
116
124
  messages = LifeBoat.read_queue("destroy_fake_test")
@@ -123,5 +131,13 @@ describe LifeBoat do
123
131
  messages= LifeBoat.read_queue("update_fake_test")
124
132
  messages.size.should == 1
125
133
  end
134
+ end
126
135
 
136
+ describe LifeBoat, " does XML" do
137
+ it "serialices the objects to xml" do
138
+ f = XMLRecord.create(:name => "Yo soy XML")
139
+ messages = LifeBoat.read_queue("create_xmlrecord_test")
140
+ messages.size.should == 1
141
+ messages[0].body.should == f.attributes.to_xml
142
+ end
127
143
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifeboat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 5
10
- version: 0.2.5
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ivan Acosta-Rubio