simply_mongo 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/{README.rdoc → README.md} +43 -12
- data/RELEASE-NOTES.md +24 -0
- data/Rakefile +8 -1
- data/lib/generators/simply_mongo/install/install_generator.rb +28 -5
- data/lib/generators/simply_mongo/install/templates/mongo.rb +1 -1
- data/lib/generators/simply_mongo/install/templates/mongo.yml +11 -7
- data/lib/simply_mongo/version.rb +1 -1
- data/lib/simply_mongo.rb +1 -0
- data/lib/tasks/simply_mongo.rake +7 -0
- data/test/enterprise/Gemfile +7 -13
- data/test/enterprise/Gemfile.lock +87 -87
- data/test/enterprise/app/assets/javascripts/enterprises.js.coffee +1 -1
- data/test/enterprise/app/controllers/enterprises_controller.rb +2 -2
- data/test/enterprise/bin/bundle +3 -0
- data/test/enterprise/bin/rails +4 -0
- data/test/enterprise/bin/rake +4 -0
- data/test/enterprise/config/application.rb +7 -16
- data/test/enterprise/config/database.yml +0 -0
- data/test/enterprise/config/environment.rb +2 -0
- data/test/enterprise/config/environments/development.rb +1 -9
- data/test/enterprise/config/environments/production.rb +3 -1
- data/test/enterprise/config/environments/test.rb +1 -2
- data/test/enterprise/config/initializers/mongo.rb +1 -1
- data/test/enterprise/config/initializers/secret_token.rb +1 -0
- data/test/enterprise/config/mongo.yml +14 -10
- data/test/enterprise/log/development.log +3768 -690
- data/test/enterprise/log/install.log +393 -0
- data/test/enterprise/tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016 +0 -0
- data/test/enterprise/tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6 +0 -0
- metadata +87 -41
- data/lib/tasks/simply_mongo_tasks.rake +0 -4
- data/test/cmd_line_client/Enterprise.json +0 -30
- data/test/cmd_line_client/client.rb +0 -128
- data/test/enterprise/script/rails +0 -6
- data/test/enterprise/tmp/pids/server.pid +0 -1
@@ -1,128 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# JSON/Rails/Mongo examples using the only the Mongo Driver in Rails
|
3
|
-
# This is a contrived example client sending JSON CRUD request to
|
4
|
-
# Mongo in a Rails Server
|
5
|
-
#
|
6
|
-
# Author:: Robert D. Birch
|
7
|
-
#
|
8
|
-
require 'json'
|
9
|
-
require 'net/http'
|
10
|
-
|
11
|
-
module SimplyMongoClient
|
12
|
-
|
13
|
-
BASE_URI= 'http://0.0.0.0:3000/enterprises/'
|
14
|
-
INPUT_FILE = './Enterprise.json'
|
15
|
-
|
16
|
-
# Reads in a JSON Enterprise document from a flat file.
|
17
|
-
# The read in JSON document string is sent to the the Rails server as a POST
|
18
|
-
def SimplyMongoClient.create(enterprise)
|
19
|
-
request = Net::HTTP::Post.new("/enterprises/create")
|
20
|
-
request['CONTENT-TYPE'] = 'application/json'
|
21
|
-
request.body = enterprise
|
22
|
-
response = Net::HTTP.new('0.0.0.0', 3000).start do |http|
|
23
|
-
http.request(request)
|
24
|
-
end
|
25
|
-
raise IOError, "Network Error #{response.message}" if response.code == 200
|
26
|
-
return response
|
27
|
-
end
|
28
|
-
|
29
|
-
# From the Rails server return all the enterprise documents stored in the Mongo Database
|
30
|
-
def SimplyMongoClient.index
|
31
|
-
uri = URI(BASE_URI)
|
32
|
-
response = Net::HTTP.get_response(uri)
|
33
|
-
raise IOError, "Network Error #{response.message}" if response.code == 200
|
34
|
-
j = JSON.parse(response.body)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Get the requested enterprise document
|
38
|
-
def SimplyMongoClient.show(id)
|
39
|
-
uri = URI(BASE_URI + "/" + id)
|
40
|
-
response = Net::HTTP.get_response(uri)
|
41
|
-
raise IOError, "Network Error #{response.message}" if response.code == 200
|
42
|
-
j = JSON.parse(response.body)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Update/Replace the enterprise document on the server
|
46
|
-
def SimplyMongoClient.update(enterprise)
|
47
|
-
request = Net::HTTP::Put.new(BASE_URI + enterprise['_id'])
|
48
|
-
request['CONTENT-TYPE'] = 'application/json'
|
49
|
-
request.set_form_data(enterprise)
|
50
|
-
response = Net::HTTP.new('0.0.0.0', 3000).start do |http |
|
51
|
-
response = http.request(request)
|
52
|
-
end
|
53
|
-
raise IOError, "Network Error #{response.message}" if response.code == 200
|
54
|
-
return response
|
55
|
-
end
|
56
|
-
|
57
|
-
# Delete the enterprise document with the given id
|
58
|
-
def SimplyMongoClient.destroy(id)
|
59
|
-
request = Net::HTTP::Delete.new(BASE_URI + "/" + id)
|
60
|
-
response = Net::HTTP.new('0.0.0.0', 3000).start do |http |
|
61
|
-
http.request(request)
|
62
|
-
end
|
63
|
-
raise IOError, "Network Error #{response.message}" if response.code == 200
|
64
|
-
return response
|
65
|
-
end
|
66
|
-
|
67
|
-
end # SimplyMongoClient
|
68
|
-
|
69
|
-
|
70
|
-
## Contrived set of example statement to create, fetch, update and delete an enterprise document
|
71
|
-
|
72
|
-
# Get all documents and print the count
|
73
|
-
puts "**LIST**"
|
74
|
-
j = SimplyMongoClient.index
|
75
|
-
puts "We start with #{j.count} enterprise documents in the Mongo collection"
|
76
|
-
puts ""
|
77
|
-
|
78
|
-
# Create an enterprise document
|
79
|
-
puts "**CREATE**"
|
80
|
-
fjson = File.open(SimplyMongoClient::INPUT_FILE)
|
81
|
-
enterprise = ""
|
82
|
-
fjson.each { |line| enterprise = enterprise + line; }
|
83
|
-
res = SimplyMongoClient.create enterprise
|
84
|
-
e = JSON.parse res.body
|
85
|
-
puts "Created one enterprise document with id: #{e['id']}"
|
86
|
-
fjson.close
|
87
|
-
puts ""
|
88
|
-
|
89
|
-
# Fetch and display the recently created enterprise document
|
90
|
-
puts "**GET**"
|
91
|
-
puts "Display created enterprise document with id: #{e['id']}"
|
92
|
-
j = SimplyMongoClient.show e['id']
|
93
|
-
puts "Show document with id #{e['id']} : #{j}"
|
94
|
-
puts ""
|
95
|
-
|
96
|
-
# Update/Replay the enterprise document by changing the email address
|
97
|
-
puts "**UPDATE**"
|
98
|
-
new_mail = "fflintstone@slaterockandgravel.com"
|
99
|
-
puts "Update document by changing home email: fflinstone@bedrock.com to : #{new_mail}"
|
100
|
-
contacts = j['contacts']
|
101
|
-
contacts.each { |c|
|
102
|
-
if c['last_name'] == 'Flintstone'
|
103
|
-
then
|
104
|
-
c['email'].each { |e|
|
105
|
-
if e['description'] == "Work Email"
|
106
|
-
then
|
107
|
-
puts "CURRENT EMAIL #{e['email']}"
|
108
|
-
e['email'] = new_mail
|
109
|
-
puts "NEW EMAIL #{e['email']}"
|
110
|
-
end
|
111
|
-
}
|
112
|
-
end
|
113
|
-
}
|
114
|
-
r = SimplyMongoClient.update j
|
115
|
-
# Fetch and display the recently updateed enterprise document
|
116
|
-
puts "Display updated enterprise document with id: #{e['id']}"
|
117
|
-
uj = SimplyMongoClient.show e['id']
|
118
|
-
puts "Show document with id #{e['id']} : #{uj}"
|
119
|
-
puts ""
|
120
|
-
|
121
|
-
# Delete the newly created enterprise document
|
122
|
-
puts "**DELETE**"
|
123
|
-
puts "Destroy one enterprise document with id: #{e['id']}"
|
124
|
-
r = SimplyMongoClient.destroy e['id']
|
125
|
-
puts "Destroy returned with a response code of : #{r.code}"
|
126
|
-
puts "Show document with id #{e['id']} "
|
127
|
-
j = SimplyMongoClient.show e['id']
|
128
|
-
puts "Document id: #{e['id']} should be deleted (empty) => #{j}"
|
@@ -1,6 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
-
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
6
|
-
require 'rails/commands'
|
@@ -1 +0,0 @@
|
|
1
|
-
16637
|