ocelot 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,5 @@
1
+ Expect constant flux until version 0.1.0.
2
+
3
+ Source at https://bitbucket.org/exussum/ocelot
4
+
5
+ Home at http://exussum.heroku.com
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/ocelot ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ require 'ocelot/cli'
data/go.rb ADDED
@@ -0,0 +1,214 @@
1
+ source Hash[
2
+ :adapter => "mysql",
3
+ :host => "patchreport-mysql.websys.aol.com",
4
+ :database => "polar_production",
5
+ :username => 'patch_r',
6
+ :password => 'p@tchprd'
7
+ ]
8
+
9
+ include File.join(Rails.root, "config", "active_spider_target.rb")
10
+
11
+ target Hash[
12
+ :adapter => "mysql",
13
+ :host => "localhost",
14
+ :database => "yo_mama",
15
+ :username => 'root'
16
+ ]
17
+
18
+ log_level "ERROR"
19
+
20
+ TARGET_ID = 18
21
+ ATTACHMENTS = 20
22
+
23
+ seeds { [
24
+ Neighborhood.find(169302),
25
+ ContentBlock.find(:all, :order => "id desc"),
26
+ ContentPage.find(:all),
27
+ Publication.find(TARGET_ID),
28
+ Publication.find(1) ] }
29
+
30
+ init do
31
+ u = User.new(:name => 'mc hammer', :email=>'import@example.com')
32
+ u.permalink = "__patch_patch_baby__"
33
+ u.save(false)
34
+ end
35
+
36
+ classes %q{
37
+ Address
38
+ Answer
39
+ Article
40
+ AssetAttachment
41
+ Author
42
+ Boundary
43
+ Category
44
+ Characteristic
45
+ UserContribution
46
+ City
47
+ Classified
48
+ AdtechAdZone
49
+ Coupon
50
+ County
51
+ Country
52
+ CouponPackage
53
+ Review
54
+ RelatedLink
55
+ Claim
56
+ ClassificationsObject
57
+ Column
58
+ Comment
59
+ ContentBlock
60
+ ContentPage
61
+ CurrentWeather
62
+ Event
63
+ Feature
64
+ InfoPage
65
+ Language
66
+ Listing
67
+ Location
68
+ Logo
69
+ Neighborhood
70
+ ObjectCounter
71
+ Pdf
72
+ Photo
73
+ Publication
74
+ PublicationAttachment
75
+ PublicationGroup
76
+ Region
77
+ Question
78
+ Schedule
79
+ State
80
+ TwitterTweet
81
+ User
82
+ Video
83
+ VideoInfo
84
+ WeatherForecast
85
+ Workflow
86
+ WorkflowChange
87
+ ZipCode
88
+ }
89
+
90
+ filter Location do |obj, collection, name|
91
+ result [] unless :locator == name
92
+ end
93
+
94
+ filter Column do |obj, collection, name|
95
+ result collection.find(:all, :limit => 3, :order => "id desc") if :articles == name
96
+ end
97
+
98
+ filter Category do |obj, collection, name|
99
+ nothing if [:classifications_objects, :all_photos, :all_videos, :all_pdfs].include? name
100
+ end
101
+
102
+ [Boundary, Borough, City, Country, County, Neighborhood, State, Zipcode].each do |c|
103
+ filter c do |obj, collection, name|
104
+ nothing if :notes != name
105
+ end
106
+ end
107
+
108
+ filter Schedule do |obj, collection, name|
109
+ nothing if :schedule_occurrences == name
110
+ end
111
+
112
+ [Announcement, Article, Classified, Coupon, Employee, Listing, Event, InfoPage].each do |c|
113
+ filter c do |obj, collection, name|
114
+ if [:all_assets,
115
+ :similarities1, :similarities2,
116
+ :links_to, :links_from,
117
+ :photos, :pdfs,
118
+ :videos, :all_photos,
119
+ :all_videos, :all_pdfs].include? name
120
+ nothing
121
+ elsif :located_locations == name
122
+ # total abuse of located_locations. grrrr
123
+ result obj.locations
124
+ elsif :assets == name
125
+ result collection.find(:all, :limit => 5)
126
+ end
127
+ end
128
+ end
129
+
130
+ filter Publication do |obj, collection, name|
131
+ if [:permissions, :listing_similarities, :publication_attachments, :claims].include? name
132
+ nothing
133
+ elsif :columns == name
134
+ result collection.find( :all, :limit => 3, :order => "id desc")
135
+ elsif [:events, :announcements, :claims, :articles, :listings, :events, :twitter_tweets, :users, :classifieds].include? name
136
+ result collection.find(:all, :limit => ATTACHMENTS, :order => "id desc")
137
+ end
138
+ end
139
+
140
+ rule Publication do |obj, *args|
141
+ persist obj
142
+ if obj.id == 1 or obj.id == TARGET_ID
143
+ inspect
144
+ end
145
+ end
146
+
147
+ rule Column do |obj|
148
+ use_target_db!
149
+ obj.user = User.find_by_email('import@example.com')
150
+ obj.publications << Publication.find(TARGET_ID)
151
+
152
+ persist obj
153
+ inspect
154
+ end
155
+
156
+ rule PublicationAttachment do |obj, pub, to|
157
+ if obj.id.nil?
158
+ pub, to = to, pub unless pub.class == Publication
159
+
160
+ obj.publication = pub
161
+ obj.object = to
162
+ persist obj
163
+ inspect
164
+ end
165
+ end
166
+
167
+ rule AssetAttachment do |obj, contained, to|
168
+ if obj.id.nil?
169
+ use_target_db!
170
+ obj.to = contained
171
+ obj.from = to
172
+ obj.user = User.find_by_email('import@example.com')
173
+ persist obj
174
+ end
175
+ end
176
+
177
+ rule User do |obj, *args|
178
+ obj.password = "123456"
179
+ obj.password_confirmation = "123456"
180
+ persist obj
181
+ end
182
+
183
+ [Question, Answer].each do |c|
184
+ rule c do |obj, *args|
185
+ user = obj.user
186
+ use_target_db!
187
+ obj.user ||= User.find_by_email('import@example.com')
188
+ persist obj
189
+ inspect
190
+ end
191
+ end
192
+
193
+ rule UserContribution do |obj, *args|
194
+ persist obj
195
+ end
196
+
197
+ rule Schedule do |obj, *args|
198
+ persist obj
199
+ use_target_db!
200
+
201
+ obj.send(:generate_occurrences_with_default_horizon!)
202
+ inspect
203
+ end
204
+
205
+ rule Video do |obj, *args|
206
+ persist obj
207
+ inspect
208
+ end
209
+
210
+ [Region, Address, Language, LocalFact, Characteristic].each do |c|
211
+ rule c do |obj, *args|
212
+ persist obj
213
+ end
214
+ end
data/lib/ocelot/cli.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  puts "Loading Rails environment..."
3
3
  require File.join(ARGV[0], 'environment')
4
4
 
5
+ require 'bundler'
5
6
  require 'ocelot/dsl'
6
7
 
7
8
  go = Ocelot::Dsl.new
data/ocelot.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "ocelot"
6
+ s.version = "0.0.1"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["spencer p"]
9
+ s.email = ["exussum@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{DBA like tool to copy a slice of data from one db to another}
12
+ s.description = %q{Extreme alpha}
13
+ s.files = `hg locate | egrep -v '^\\.'`.split("\n")
14
+ s.executables = "ocelot"
15
+
16
+ s.require_paths = ["lib"]
17
+ end
@@ -0,0 +1,79 @@
1
+ module Test
2
+ require 'rubygems'
3
+ require 'flow'
4
+ require 'test/unit'
5
+
6
+ include Flow
7
+
8
+ class BlockRule < Rule
9
+ def initialize(status=nil, event=nil, &block)
10
+ @event = event
11
+ @status = status
12
+ @block = block
13
+ end
14
+
15
+ def transition(status, event)
16
+ return @block.call(status,event)
17
+ end
18
+
19
+ def match?(status, event)
20
+ status == @status and event == @event
21
+ end
22
+ end
23
+
24
+ class WorfklowTest < Test::Unit::TestCase
25
+ def setup
26
+ @target = Flow::Workflow.new
27
+ end
28
+
29
+ def test_single_match
30
+ r1 = BlockRule.new("moving", "yellow") { "slowing" }
31
+ r2 = BlockRule.new("slowing", "red") { "stop" }
32
+ r3 = BlockRule.new("stop", "green") { "moving" }
33
+ r4 = BlockRule.new("stop", "ufo") { "abducted" }
34
+
35
+
36
+ @target.rules = [r1,r2,r3,r4]
37
+ @target.status = "stop"
38
+
39
+ assert_equal(@target.process("green"), "moving", "stop + green <> moving")
40
+ assert_equal(@target.process("green"), "moving", "unrecognized combo <> last status")
41
+ assert_equal(@target.process("yellow"), "slowing", "moving + yellow <> slowing")
42
+ assert_equal(@target.process("red"), "stop", "slowing + red <> stop")
43
+ assert_equal(@target.process("ufo"), "abducted", "stop + ufo <> abducted")
44
+ assert_equal(@target.process("green"), "abducted", "green + ufo <> abducted")
45
+ end
46
+
47
+ def test_default_match
48
+ r1 = BlockRule.new("start","nudge") { "middle" }
49
+ d1 = BlockRule.new { "end" }
50
+
51
+ @target.rules = [r1]
52
+ @target.default_rule = d1
53
+ @target.status = "start"
54
+
55
+ assert_equal(@target.process("nudge"), "middle", "start + nudge <> middle" )
56
+ assert_equal(@target.process("garbage"), "end", "default rule didn't push to the end")
57
+ end
58
+
59
+ def test_multi_match
60
+ r1 = BlockRule.new("moving", "yellow") { "slowing" }
61
+ r2 = BlockRule.new("slowing", "red") { "stop" }
62
+ r3 = BlockRule.new("stop", "green") { "moving" }
63
+ r4 = BlockRule.new("stop", "ufo") { "abducted" }
64
+
65
+
66
+ @target.rules = [r1,r2,r3,r4]
67
+ @target.status = "stop"
68
+ @target.multi_match = true
69
+
70
+ assert_equal(@target.process("green"), "moving", "stop + green <> moving")
71
+ assert_equal(@target.process("green"), "moving", "unrecognized combo <> last status")
72
+ assert_equal(@target.process("yellow"), "slowing", "moving + yellow <> slowing")
73
+ assert_equal(@target.process("red"), "stop", "slowing + red <> stop")
74
+ assert_equal(@target.process("ufo"), "abducted", "stop + ufo <> abducted")
75
+ assert_equal(@target.process("green"), "abducted", "green + ufo <> abducted")
76
+ end
77
+
78
+ end
79
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ocelot
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.0
5
+ version: 0.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - spencer p
@@ -10,27 +10,33 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-17 00:00:00 -04:00
13
+ date: 2011-04-18 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
17
17
  description: Extreme alpha
18
18
  email:
19
19
  - exussum@gmail.com
20
- executables: []
21
-
20
+ executables:
21
+ - ocelot
22
22
  extensions: []
23
23
 
24
24
  extra_rdoc_files: []
25
25
 
26
26
  files:
27
+ - README
28
+ - Rakefile
29
+ - bin/ocelot
30
+ - go.rb
31
+ - lib/ocelot.rb
27
32
  - lib/ocelot/cli.rb
28
33
  - lib/ocelot/database.rb
29
34
  - lib/ocelot/dsl.rb
30
35
  - lib/ocelot/graph.rb
31
36
  - lib/ocelot/processor.rb
32
37
  - lib/ocelot/rules.rb
33
- - lib/ocelot.rb
38
+ - ocelot.gemspec
39
+ - test/flow/workflow_test.rb
34
40
  has_rdoc: true
35
41
  homepage: ""
36
42
  licenses: []