mongify 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.yardopts +3 -0
  4. data/CHANGELOG.rdoc +5 -0
  5. data/Gemfile.lock +52 -6
  6. data/LICENSE +1 -1
  7. data/README.rdoc +29 -11
  8. data/Rakefile +37 -9
  9. data/features/options.feature +2 -0
  10. data/features/print.feature +1 -1
  11. data/features/process.feature +10 -1
  12. data/features/step_definitions/process_steps.rb +11 -1
  13. data/features/support/env.rb +1 -1
  14. data/lib/mongify/cli/application.rb +7 -7
  15. data/lib/mongify/cli/command/worker.rb +18 -14
  16. data/lib/mongify/cli/options.rb +2 -1
  17. data/lib/mongify/configuration.rb +5 -5
  18. data/lib/mongify/database/base_connection.rb +6 -6
  19. data/lib/mongify/database/column.rb +40 -40
  20. data/lib/mongify/database/data_row.rb +9 -9
  21. data/lib/mongify/database/no_sql_connection.rb +61 -35
  22. data/lib/mongify/database/sql_connection.rb +44 -15
  23. data/lib/mongify/database/table.rb +62 -46
  24. data/lib/mongify/exceptions.rb +5 -5
  25. data/lib/mongify/progressbar.rb +15 -15
  26. data/lib/mongify/status.rb +8 -8
  27. data/lib/mongify/translation.rb +19 -17
  28. data/lib/mongify/translation/process.rb +16 -123
  29. data/lib/mongify/translation/processor_common.rb +132 -0
  30. data/lib/mongify/translation/sync.rb +112 -0
  31. data/lib/mongify/ui.rb +9 -9
  32. data/lib/mongify/version.rb +1 -1
  33. data/mongify.gemspec +4 -2
  34. data/spec/files/deleting_fields_from_embedding_parent_translation.rb +19 -0
  35. data/spec/files/embedded_parent_translation.rb +1 -1
  36. data/spec/mongify/cli/application_spec.rb +1 -1
  37. data/spec/mongify/cli/options_spec.rb +1 -1
  38. data/spec/mongify/cli/worker_command_spec.rb +46 -17
  39. data/spec/mongify/database/column_spec.rb +21 -21
  40. data/spec/mongify/database/data_row_spec.rb +11 -11
  41. data/spec/mongify/database/no_sql_connection_spec.rb +61 -27
  42. data/spec/mongify/database/sql_connection_spec.rb +62 -2
  43. data/spec/mongify/database/table_spec.rb +53 -29
  44. data/spec/mongify/translation/printer_spec.rb +2 -2
  45. data/spec/mongify/translation/process_spec.rb +50 -34
  46. data/spec/mongify/translation/sync_spec.rb +184 -0
  47. data/spec/mongify/translation_spec.rb +8 -8
  48. data/spec/mongify/ui_spec.rb +12 -12
  49. data/spec/mongify_spec.rb +1 -1
  50. data/spec/spec_helper.rb +8 -1
  51. data/spec/support/config_reader.rb +2 -2
  52. data/spec/support/database_generator.rb +68 -25
  53. data/spec/support/database_output.txt +17 -0
  54. metadata +41 -6
@@ -9,67 +9,67 @@ describe Mongify::UI do
9
9
  @config.out_stream = @out
10
10
  @config.in_stream = @in
11
11
  end
12
-
12
+
13
13
  it "should add puts to out stream" do
14
14
  @ui.puts "hello"
15
15
  @out.string.should == "hello\n"
16
16
  end
17
-
17
+
18
18
  it "should add print to out stream without newline" do
19
19
  @ui.print "hello"
20
20
  @out.string.should == "hello"
21
21
  end
22
-
22
+
23
23
  it "should fetch gets from in stream" do
24
24
  @in.puts "bar"
25
25
  @in.rewind
26
26
  @ui.gets.should == "bar\n"
27
27
  end
28
-
28
+
29
29
  it "should gets should return empty string if no input" do
30
30
  @config.in_stream = nil
31
31
  @ui.gets.should == ""
32
32
  end
33
-
33
+
34
34
  it "should request text input" do
35
35
  @in.puts "bar"
36
36
  @in.rewind
37
37
  @ui.request("foo").should == "bar"
38
38
  @out.string.should == "foo"
39
39
  end
40
-
40
+
41
41
  it "should ask for yes/no and return true when yes" do
42
42
  @ui.should_receive(:request).with('foo? [yn] ').and_return('y')
43
43
  @ui.ask("foo?").should be_true
44
44
  end
45
-
45
+
46
46
  it "should ask for yes/no and return false when no" do
47
47
  @ui.stub(:request).and_return('n')
48
48
  @ui.ask("foo?").should be_false
49
49
  end
50
-
50
+
51
51
  it "should ask for yes/no and return false for any input" do
52
52
  @ui.stub(:request).and_return('aklhasdf')
53
53
  @ui.ask("foo?").should be_false
54
54
  end
55
-
55
+
56
56
  it "should add WARNING to a warn message" do
57
57
  @ui.warn "hello"
58
58
  @out.string.should == "WARNING: hello\n"
59
59
  end
60
-
60
+
61
61
  context "terminal_helper" do
62
62
  it "should return a HighLine class" do
63
63
  @ui.terminal_helper.should be_a_kind_of HighLine
64
64
  end
65
65
  end
66
-
66
+
67
67
  context "abort" do
68
68
  it "should abort program execution" do
69
69
  Kernel.should_receive(:abort)
70
70
  @ui.abort "hacker!"
71
71
  end
72
-
72
+
73
73
  it "should output message" do
74
74
  Kernel.stub(:abort)
75
75
  @ui.abort "hacker!"
@@ -6,7 +6,7 @@ describe Mongify do
6
6
  Mongify.root = Dir.pwd
7
7
  Mongify.root.should == Dir.pwd
8
8
  end
9
-
9
+
10
10
  it "should raise error if not defined" do
11
11
  Mongify.root = nil
12
12
  lambda { Mongify.root }.should raise_error(Mongify::RootMissing)
@@ -19,4 +19,11 @@ Dir['./spec/support/**/*.rb'].map {|f| require f}
19
19
 
20
20
  Mongify.root = File.dirname(File.dirname(__FILE__))
21
21
 
22
- ::DATABASE_PRINT = File.read(File.dirname(File.expand_path(__FILE__)) + '/support/database_output.txt')
22
+ ::DATABASE_PRINT = File.read(File.dirname(File.expand_path(__FILE__)) + '/support/database_output.txt')
23
+
24
+ # redirect deprecation warnings of rspec to a file
25
+ RSpec.configure do |rspec|
26
+ rspec.deprecation_stream = 'log/deprecations.log'
27
+ end
28
+ # mute the deprecation message from I18n
29
+ I18n.enforce_available_locales = false
@@ -8,12 +8,12 @@ class ConfigReader
8
8
  raise ">>> Can't find #{filepath} -- unable to read config file <<<"
9
9
  end
10
10
  end
11
-
11
+
12
12
  # Return true if there is an instance variable under that name
13
13
  def responses_to?(key)
14
14
  instance_variable_get("@#{key}") ? instance_variable_get("@#{key}") : super(key)
15
15
  end
16
-
16
+
17
17
  # Returns value of instance variable if set
18
18
  def method_missing(meth, *args, &blk)
19
19
  value = instance_variable_get("@#{meth}")
@@ -2,22 +2,33 @@
2
2
  class DatabaseGenerator
3
3
  # Returns a mysql connection (using the database.yml)
4
4
  def self.mysql_connection
5
- @sql_connection ||= Mongify::Database::SqlConnection.new( :adapter => CONNECTION_CONFIG.mysql['adapter'],
6
- :host => CONNECTION_CONFIG.mysql['host'],
5
+ @sql_connection = Mongify::Database::SqlConnection.new( :adapter => CONNECTION_CONFIG.mysql['adapter'],
6
+ :host => CONNECTION_CONFIG.mysql['host'],
7
7
  :port => CONNECTION_CONFIG.mysql['port'],
8
8
  :username => CONNECTION_CONFIG.mysql['username'],
9
9
  :password => CONNECTION_CONFIG.mysql['password'],
10
10
  :database => CONNECTION_CONFIG.mysql['database']
11
11
  )
12
12
  end
13
-
13
+
14
+ # Returns a postgresql connection (using the database.yml)
15
+ def self.postgresql_connection
16
+ @sql_connection = Mongify::Database::SqlConnection.new( :adapter => CONNECTION_CONFIG.postgresql['adapter'],
17
+ :host => CONNECTION_CONFIG.postgresql['host'],
18
+ :port => CONNECTION_CONFIG.postgresql['port'],
19
+ :username => CONNECTION_CONFIG.postgresql['username'],
20
+ :password => CONNECTION_CONFIG.postgresql['password'],
21
+ :database => CONNECTION_CONFIG.postgresql['database']
22
+ )
23
+ end
24
+
14
25
  # Returns a sqlite connection (using the database.yml )
15
26
  def self.sqlite_connection
16
27
  @db_path = File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), CONNECTION_CONFIG.sqlite['database'])
17
-
28
+
18
29
  @sqlite_connecton ||= Mongify::Database::SqlConnection.new(:adapter => CONNECTION_CONFIG.sqlite['adapter'], :database => @db_path)
19
30
  end
20
-
31
+
21
32
  # Creates a new mysql database (and deletes the old one)
22
33
  def self.sqlite(include_data=true)
23
34
  File.delete(sqlite_connection.database) if File.exists?(sqlite_connection.database)
@@ -44,14 +55,14 @@ class DatabaseGenerator
44
55
  t.integer :user_id
45
56
  t.timestamps
46
57
  end
47
-
58
+
48
59
  conn.create_table(:preferences, :id => false) do |t|
49
60
  t.string :id
50
61
  t.integer :user_id
51
62
  t.boolean :notify_by_email
52
63
  t.timestamps
53
64
  end
54
-
65
+
55
66
  conn.create_table(:notes) do |t|
56
67
  t.integer :user_id
57
68
  t.integer :notable_id
@@ -59,48 +70,60 @@ class DatabaseGenerator
59
70
  t.text :body
60
71
  t.timestamps
61
72
  end
62
-
73
+
74
+ conn.create_table(:teams) do |t|
75
+ t.string :name
76
+ t.string :phone
77
+ t.timestamps
78
+ end
79
+
80
+ conn.create_table(:coaches) do |t|
81
+ t.integer :team_id
82
+ t.string :first_name, :last_name
83
+ t.timestamps
84
+ end
85
+
63
86
  if include_data
64
-
87
+
65
88
  #Users
66
- [
89
+ [
67
90
  {:first_name => 'Timmy', :last_name => 'Zuza'},
68
91
  {:first_name => 'Bob', :last_name => 'Smith'},
69
92
  {:first_name => 'Joe', :last_name => 'Franklin'}
70
93
  ].each do |values|
71
94
  conn.insert("INSERT INTO users (first_name, last_name, created_at, updated_at) VALUES ('#{values[:first_name]}', '#{values[:last_name]}', '#{Time.now.to_s(:db)}', '#{Time.now.to_s(:db)}')")
72
95
  end
73
-
96
+
74
97
  #Posts
75
- [
98
+ [
76
99
  {:title => 'First Post', :owner_id => 1, :body => 'First Post Body', :published_at => (Time.now - 2).to_s(:db)},
77
100
  {:title => 'Second Post', :owner_id => 1, :body => 'Second Post Body', :published_at => (Time.now - 1).to_s(:db)},
78
- {:title => 'Third Post', :owner_id => 2, :body => 'Thrid Post Body', :published_at => (Time.now).to_s(:db)},
101
+ {:title => 'Third Post', :owner_id => 2, :body => 'Third Post Body', :published_at => (Time.now).to_s(:db)},
79
102
  ].each do |v|
80
- conn.insert("INSERT INTO posts (title, owner_id, body, published_at, created_at, updated_at)
103
+ conn.insert("INSERT INTO posts (title, owner_id, body, published_at, created_at, updated_at)
81
104
  VALUES ('#{v[:title]}', #{v[:owner_id]}, '#{v[:body]}', '#{v[:published_at]}', '#{Time.now.to_s(:db)}', '#{Time.now.to_s(:db)}')")
82
105
  end
83
-
106
+
84
107
  #Comments
85
108
  [
86
109
  {:post_id => 1, :user_id => 1, :body => 'First Comment Body'},
87
110
  {:post_id => 2, :user_id => 1, :body => 'Second Comment Body'},
88
- {:post_id => 2, :user_id => 2, :body => 'Thrid Comment Body'},
111
+ {:post_id => 2, :user_id => 2, :body => 'Third Comment Body'},
89
112
  ].each do |v|
90
- conn.insert("INSERT INTO comments (body, post_id, user_id, created_at, updated_at)
113
+ conn.insert("INSERT INTO comments (body, post_id, user_id, created_at, updated_at)
91
114
  VALUES ('#{v[:body]}', #{v[:post_id]}, #{v[:user_id]}, '#{Time.now.to_s(:db)}', '#{Time.now.to_s(:db)}')")
92
115
  end
93
-
116
+
94
117
  #Preferences
95
118
  [
96
119
  {:user_id => 1, :notify_by_email => true},
97
120
  {:user_id => 2, :notify_by_email => true},
98
121
  {:user_id => 3, :notify_by_email => false},
99
122
  ].each_with_index do |v, idx|
100
- conn.insert("INSERT INTO preferences (id, user_id, notify_by_email, created_at, updated_at)
123
+ conn.insert("INSERT INTO preferences (id, user_id, notify_by_email, created_at, updated_at)
101
124
  VALUES ('p#{idx+1}',#{v[:user_id]}, '#{v[:notify_by_email]}', '#{Time.now.to_s(:db)}', '#{Time.now.to_s(:db)}')")
102
125
  end
103
-
126
+
104
127
  #Notes
105
128
  [
106
129
  {:user_id => 1, :body => 'note 1', :notable_id => 1, :notable_type => 'Post'},
@@ -108,20 +131,40 @@ class DatabaseGenerator
108
131
  {:user_id => 2, :body => 'note 3', :notable_id => 1, :notable_type => 'User'},
109
132
  {:user_id => 3, :body => 'note 4', :notable_id => 2, :notable_type => 'User'},
110
133
  ].each do |v|
111
- conn.insert("INSERT INTO notes (user_id, body, notable_id, notable_type, created_at, updated_at)
134
+ conn.insert("INSERT INTO notes (user_id, body, notable_id, notable_type, created_at, updated_at)
112
135
  VALUES (#{v[:user_id]}, '#{v[:body]}', #{v[:notable_id]}, '#{v[:notable_type]}', '#{Time.now.to_s(:db)}', '#{Time.now.to_s(:db)}')")
113
136
  end
114
-
137
+
138
+ #Teams
139
+ [
140
+ {:name => 'Athens Avengers', :phone => '+1122334455'},
141
+ {:name => 'Berlin Bashers', :phone => '+1234567890'},
142
+ {:name => 'Copenhagen Crushers', :phone => '+1112223334'}
143
+ ].each do |v|
144
+ conn.insert("INSERT INTO teams (name, phone, created_at, updated_at)
145
+ VALUES ('#{v[:name]}', '#{v[:phone]}', '#{Time.now.to_s(:db)}', '#{Time.now.to_s(:db)}')")
146
+ end
147
+
148
+ #Coaches
149
+ [
150
+ {:team_id => 1, :first_name => 'Alice', :last_name => 'Adams'},
151
+ {:team_id => 2, :first_name => 'Bob', :last_name => 'Brown'},
152
+ {:team_id => 3, :first_name => 'Carl', :last_name => 'Cooper'}
153
+ ].each do |v|
154
+ conn.insert("INSERT INTO coaches (team_id, first_name, last_name, created_at, updated_at)
155
+ VALUES (#{v[:team_id]}, '#{v[:first_name]}', '#{v[:last_name]}', '#{Time.now.to_s(:db)}', '#{Time.now.to_s(:db)}')")
156
+ end
157
+
115
158
  end
116
-
159
+
117
160
  sqlite_connection.database
118
161
  end
119
-
162
+
120
163
  # Drops the database in mongo
121
164
  def self.clear_mongodb
122
165
  mongo_connection.connection.drop_database mongo_connection.database
123
166
  end
124
-
167
+
125
168
  # Returns a mongo connection (based on the database.yml)
126
169
  def self.mongo_connection
127
170
  @mongodb_connection ||= Mongify::Database::NoSqlConnection.new(:host => CONNECTION_CONFIG.mongo['host'],
@@ -43,3 +43,20 @@ table "notes" do
43
43
  column "updated_at", :datetime
44
44
  end
45
45
 
46
+ table "teams" do
47
+ column "id", :key, :as => :integer
48
+ column "name", :string
49
+ column "phone", :string
50
+ column "created_at", :datetime
51
+ column "updated_at", :datetime
52
+ end
53
+
54
+ table "coaches" do
55
+ column "id", :key, :as => :integer
56
+ column "team_id", :integer, :references => "teams"
57
+ column "first_name", :string
58
+ column "last_name", :string
59
+ column "created_at", :datetime
60
+ column "updated_at", :datetime
61
+ end
62
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kalek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-24 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.5.3
139
139
  - !ruby/object:Gem::Dependency
140
- name: sqlite3-ruby
140
+ name: sqlite3
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '>='
@@ -150,20 +150,34 @@ dependencies:
150
150
  - - '>='
151
151
  - !ruby/object:Gem::Version
152
152
  version: '1.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: pg
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0.17'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0.17'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: mysql2
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - ~>
158
172
  - !ruby/object:Gem::Version
159
- version: 0.2.7
173
+ version: 0.3.1
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - ~>
165
179
  - !ruby/object:Gem::Version
166
- version: 0.2.7
180
+ version: 0.3.1
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: watchr
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +206,20 @@ dependencies:
192
206
  - - '>='
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: pry-plus
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - '>='
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - '>='
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
195
223
  description: Mongify allows you to map your sql data into a mongodb document database
196
224
  with a simple DSL.
197
225
  email:
@@ -205,6 +233,7 @@ extra_rdoc_files:
205
233
  files:
206
234
  - .gitignore
207
235
  - .rspec
236
+ - .yardopts
208
237
  - CHANGELOG.rdoc
209
238
  - Gemfile
210
239
  - Gemfile.lock
@@ -240,11 +269,14 @@ files:
240
269
  - lib/mongify/translation.rb
241
270
  - lib/mongify/translation/printer.rb
242
271
  - lib/mongify/translation/process.rb
272
+ - lib/mongify/translation/processor_common.rb
273
+ - lib/mongify/translation/sync.rb
243
274
  - lib/mongify/ui.rb
244
275
  - lib/mongify/version.rb
245
276
  - mongify.gemspec
246
277
  - spec/default.watch
247
278
  - spec/files/base_configuration.rb
279
+ - spec/files/deleting_fields_from_embedding_parent_translation.rb
248
280
  - spec/files/embedded_parent_translation.rb
249
281
  - spec/files/translation.rb
250
282
  - spec/mongify/cli/application_spec.rb
@@ -262,6 +294,7 @@ files:
262
294
  - spec/mongify/status_spec.rb
263
295
  - spec/mongify/translation/printer_spec.rb
264
296
  - spec/mongify/translation/process_spec.rb
297
+ - spec/mongify/translation/sync_spec.rb
265
298
  - spec/mongify/translation_spec.rb
266
299
  - spec/mongify/ui_spec.rb
267
300
  - spec/mongify_spec.rb
@@ -297,7 +330,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
330
  version: '0'
298
331
  requirements: []
299
332
  rubyforge_project:
300
- rubygems_version: 2.1.11
333
+ rubygems_version: 2.0.14
301
334
  signing_key:
302
335
  specification_version: 4
303
336
  summary: Translate your SQL data to MongoDB with ease
@@ -311,6 +344,7 @@ test_files:
311
344
  - features/support/env.rb
312
345
  - spec/default.watch
313
346
  - spec/files/base_configuration.rb
347
+ - spec/files/deleting_fields_from_embedding_parent_translation.rb
314
348
  - spec/files/embedded_parent_translation.rb
315
349
  - spec/files/translation.rb
316
350
  - spec/mongify/cli/application_spec.rb
@@ -328,6 +362,7 @@ test_files:
328
362
  - spec/mongify/status_spec.rb
329
363
  - spec/mongify/translation/printer_spec.rb
330
364
  - spec/mongify/translation/process_spec.rb
365
+ - spec/mongify/translation/sync_spec.rb
331
366
  - spec/mongify/translation_spec.rb
332
367
  - spec/mongify/ui_spec.rb
333
368
  - spec/mongify_spec.rb