mongify-mongoid 1.0.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.
- data/.gitignore +20 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +17 -0
- data/bin/mongify_mongoid +18 -0
- data/lib/mongify/mongoid.rb +16 -0
- data/lib/mongify/mongoid/cli.rb +9 -0
- data/lib/mongify/mongoid/cli/application.rb +60 -0
- data/lib/mongify/mongoid/cli/command/help.rb +22 -0
- data/lib/mongify/mongoid/cli/command/version.rb +21 -0
- data/lib/mongify/mongoid/cli/command/worker.rb +51 -0
- data/lib/mongify/mongoid/cli/options.rb +87 -0
- data/lib/mongify/mongoid/exceptions.rb +30 -0
- data/lib/mongify/mongoid/generator.rb +117 -0
- data/lib/mongify/mongoid/model.rb +137 -0
- data/lib/mongify/mongoid/model/field.rb +79 -0
- data/lib/mongify/mongoid/model/relation.rb +60 -0
- data/lib/mongify/mongoid/printer.rb +58 -0
- data/lib/mongify/mongoid/templates/mongoid.rb.erb +33 -0
- data/lib/mongify/mongoid/ui.rb +64 -0
- data/lib/mongify/mongoid/version.rb +6 -0
- data/mongify-mongoid.gemspec +34 -0
- data/spec/files/translation.rb +44 -0
- data/spec/lib/mongify/mongoid/cli/command/worker_spec.rb +45 -0
- data/spec/lib/mongify/mongoid/generator_spec.rb +123 -0
- data/spec/lib/mongify/mongoid/model/field_spec.rb +31 -0
- data/spec/lib/mongify/mongoid/model/relation_spec.rb +42 -0
- data/spec/lib/mongify/mongoid/model_spec.rb +146 -0
- data/spec/lib/mongify/mongoid/printer_spec.rb +57 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/custom_matchers.rb +47 -0
- metadata +214 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongify::Mongoid::Printer do
|
4
|
+
let(:output_dir){File.expand_path('../../../files/tmp', File.dirname(__FILE__))}
|
5
|
+
subject(:printer){ Mongify::Mongoid::Printer.new([], output_dir) }
|
6
|
+
it "should write" do
|
7
|
+
expect { printer.write }.to_not raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
context "file output" do
|
11
|
+
let(:model){Mongify::Mongoid::Model.new(table_name: "users", class_name: "User")}
|
12
|
+
subject(:printer){ Mongify::Mongoid::Printer.new({user: model}, output_dir) }
|
13
|
+
|
14
|
+
context "content" do
|
15
|
+
before(:each) do
|
16
|
+
printer.stub(:save_file)
|
17
|
+
end
|
18
|
+
it "should be include a class" do
|
19
|
+
output = printer.send(:render_file, model)
|
20
|
+
output.should include("class #{model.name}")
|
21
|
+
end
|
22
|
+
it "should have fields" do
|
23
|
+
model.stub(:fields).and_return({first_name: Mongify::Mongoid::Model::Field.new("first_name", "String")})
|
24
|
+
output = printer.send(:render_file, model)
|
25
|
+
output.should include("field :first_name, type: String")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have relations" do
|
29
|
+
model.stub(:relations).and_return([Mongify::Mongoid::Model::Relation.new(:embedded_in, "posts")])
|
30
|
+
output = printer.send(:render_file, model)
|
31
|
+
output.should include("embedded_in :posts")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should sort relations" do
|
35
|
+
model.stub(:relations).and_return([
|
36
|
+
Mongify::Mongoid::Model::Relation.new(:embeds_many, "posts"),
|
37
|
+
Mongify::Mongoid::Model::Relation.new(:has_many, "comments"),
|
38
|
+
Mongify::Mongoid::Model::Relation.new(:embeds_many, "addons"),
|
39
|
+
])
|
40
|
+
output = printer.send(:render_file, model)
|
41
|
+
output.gsub(/^(\s+)/, "").should include(%q{
|
42
|
+
embeds_many :posts
|
43
|
+
embeds_many :addons
|
44
|
+
has_many :comments})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
it "should create a file" do
|
50
|
+
printer.write
|
51
|
+
Dir["#{output_dir}/*.rb"].count { |file| File.file?(file) }.should == printer.models.count
|
52
|
+
end
|
53
|
+
end
|
54
|
+
after(:each) do
|
55
|
+
FileUtils.rm Dir["#{output_dir}/*.rb"]
|
56
|
+
end
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
3
|
+
require 'mongify/mongoid'
|
4
|
+
require 'mongify/mongoid/cli'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'bundler'
|
8
|
+
Bundler.setup
|
9
|
+
rescue LoadError
|
10
|
+
puts "Need to install bundler 1.0. 'gem install bundler'"
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rspec/core'
|
14
|
+
Dir['./spec/support/**/*.rb'].map {|f| require f}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
RSpec::Matchers.define :have_field do |expected|
|
2
|
+
chain :of_type do |type|
|
3
|
+
@type = type
|
4
|
+
end
|
5
|
+
|
6
|
+
match do |model|
|
7
|
+
has_field = model.fields.has_key?(expected.to_sym)
|
8
|
+
|
9
|
+
if @type
|
10
|
+
has_field && (model.fields[expected.to_sym].type == @type)
|
11
|
+
else
|
12
|
+
has_field
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
description do
|
17
|
+
if @type
|
18
|
+
"have field \"#{expected}\" of type \"#{@type}\""
|
19
|
+
else
|
20
|
+
"have field \"#{expected}\""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
RSpec::Matchers.define :have_relation do |expected|
|
26
|
+
chain :for_association do |association|
|
27
|
+
@association = association
|
28
|
+
end
|
29
|
+
|
30
|
+
match do |model|
|
31
|
+
relation = model.relations.find { |rel| rel.name == expected.to_s }
|
32
|
+
|
33
|
+
if @association
|
34
|
+
relation && (relation.association == @association.to_s || relation.association == @association.to_s.singularize)
|
35
|
+
else
|
36
|
+
relation
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
description do
|
41
|
+
if @association
|
42
|
+
"have relation \"#{expected}\" for association \"#{@association}\""
|
43
|
+
else
|
44
|
+
"have relation \"#{expected}\""
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,214 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongify-mongoid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Kalek
|
9
|
+
- Afolabi Badmos
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-05-28 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
prerelease: false
|
17
|
+
name: mongify
|
18
|
+
type: :runtime
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
none: false
|
25
|
+
requirement: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
none: false
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
prerelease: false
|
33
|
+
name: bundler
|
34
|
+
type: :development
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.3'
|
40
|
+
none: false
|
41
|
+
requirement: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
none: false
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
prerelease: false
|
49
|
+
name: rspec
|
50
|
+
type: :development
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
none: false
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
prerelease: false
|
65
|
+
name: rake
|
66
|
+
type: :development
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
none: false
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
none: false
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
prerelease: false
|
81
|
+
name: guard-rspec
|
82
|
+
type: :development
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
none: false
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
none: false
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
prerelease: false
|
97
|
+
name: yard
|
98
|
+
type: :development
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
none: false
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
none: false
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
prerelease: false
|
113
|
+
name: redcarpet
|
114
|
+
type: :development
|
115
|
+
version_requirements: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ! '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
none: false
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
none: false
|
127
|
+
description: Generates Mongoid Models from the Mongify translation file
|
128
|
+
email:
|
129
|
+
- andrew.kalek@anlek.com
|
130
|
+
- afolabi@badmos.com
|
131
|
+
executables:
|
132
|
+
- mongify_mongoid
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files:
|
135
|
+
- CHANGELOG.md
|
136
|
+
- README.md
|
137
|
+
files:
|
138
|
+
- .gitignore
|
139
|
+
- .yardopts
|
140
|
+
- CHANGELOG.md
|
141
|
+
- Gemfile
|
142
|
+
- Guardfile
|
143
|
+
- LICENSE.txt
|
144
|
+
- README.md
|
145
|
+
- Rakefile
|
146
|
+
- bin/mongify_mongoid
|
147
|
+
- lib/mongify/mongoid.rb
|
148
|
+
- lib/mongify/mongoid/cli.rb
|
149
|
+
- lib/mongify/mongoid/cli/application.rb
|
150
|
+
- lib/mongify/mongoid/cli/command/help.rb
|
151
|
+
- lib/mongify/mongoid/cli/command/version.rb
|
152
|
+
- lib/mongify/mongoid/cli/command/worker.rb
|
153
|
+
- lib/mongify/mongoid/cli/options.rb
|
154
|
+
- lib/mongify/mongoid/exceptions.rb
|
155
|
+
- lib/mongify/mongoid/generator.rb
|
156
|
+
- lib/mongify/mongoid/model.rb
|
157
|
+
- lib/mongify/mongoid/model/field.rb
|
158
|
+
- lib/mongify/mongoid/model/relation.rb
|
159
|
+
- lib/mongify/mongoid/printer.rb
|
160
|
+
- lib/mongify/mongoid/templates/mongoid.rb.erb
|
161
|
+
- lib/mongify/mongoid/ui.rb
|
162
|
+
- lib/mongify/mongoid/version.rb
|
163
|
+
- mongify-mongoid.gemspec
|
164
|
+
- spec/files/translation.rb
|
165
|
+
- spec/lib/mongify/mongoid/cli/command/worker_spec.rb
|
166
|
+
- spec/lib/mongify/mongoid/generator_spec.rb
|
167
|
+
- spec/lib/mongify/mongoid/model/field_spec.rb
|
168
|
+
- spec/lib/mongify/mongoid/model/relation_spec.rb
|
169
|
+
- spec/lib/mongify/mongoid/model_spec.rb
|
170
|
+
- spec/lib/mongify/mongoid/printer_spec.rb
|
171
|
+
- spec/spec_helper.rb
|
172
|
+
- spec/support/custom_matchers.rb
|
173
|
+
homepage: https://github.com/anlek/mongify-mongoid
|
174
|
+
licenses:
|
175
|
+
- MIT
|
176
|
+
post_install_message:
|
177
|
+
rdoc_options: []
|
178
|
+
require_paths:
|
179
|
+
- lib
|
180
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - ! '>='
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
segments:
|
185
|
+
- 0
|
186
|
+
hash: 2797947148386353191
|
187
|
+
version: '0'
|
188
|
+
none: false
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ! '>='
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
hash: 2797947148386353191
|
196
|
+
version: '0'
|
197
|
+
none: false
|
198
|
+
requirements: []
|
199
|
+
rubyforge_project:
|
200
|
+
rubygems_version: 1.8.23
|
201
|
+
signing_key:
|
202
|
+
specification_version: 3
|
203
|
+
summary: Generates Mongoid Models from the Mongify translation file
|
204
|
+
test_files:
|
205
|
+
- spec/files/translation.rb
|
206
|
+
- spec/lib/mongify/mongoid/cli/command/worker_spec.rb
|
207
|
+
- spec/lib/mongify/mongoid/generator_spec.rb
|
208
|
+
- spec/lib/mongify/mongoid/model/field_spec.rb
|
209
|
+
- spec/lib/mongify/mongoid/model/relation_spec.rb
|
210
|
+
- spec/lib/mongify/mongoid/model_spec.rb
|
211
|
+
- spec/lib/mongify/mongoid/printer_spec.rb
|
212
|
+
- spec/spec_helper.rb
|
213
|
+
- spec/support/custom_matchers.rb
|
214
|
+
has_rdoc:
|