replica_connect 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/lib/replica_connect.rb +50 -0
- data/lib/replica_connect/version.rb +3 -0
- data/replica_connect.gemspec +20 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDU3YThlZTdkMDYyYTA1OTA5YTlmZTZjNWNlZTU5NzQwNmRmODI3Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDc1MGI2N2QzNjQzODQ4MmZhZmNjNDU1NGJjNzA5NTQ2NDRjMTFjMQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OTEyNDc5NTY2YWU2NWQ1ZTk0Y2VjZDI4N2JkOWEwM2UzMTc5NGFkOTE2NjZk
|
10
|
+
ZjI3MjBmMzhiYmFmMTYxMTNjMjMxOGRjMWZmMTJhMDZkYjQwYjI2YzE3Mzlk
|
11
|
+
MTI0OTRmOWMyMzk0ZjhiZmU4MWFlNGZkMjU2YzQ4M2UyMWFiY2Q=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NjJjODYwNWFjMmI5YWY5NDkzZmY1MTQ2OTFiNGRhNDlkMDMwZWQ0NTBlOTlj
|
14
|
+
NDA3NmQ1Njc0MzMzM2VmNzJhYWYwMGE4ZWViZGFhNDc0ODlkZTBiNDg2YTE5
|
15
|
+
ZGFkNGY1OTNlMzQ2M2E0NjFlNmJkZDAwZjQ0M2JhODZhOTQxMWQ=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Solomon
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# ReplicaConnect
|
2
|
+
|
3
|
+
This gem will allow you to easily create a connection to a database in
|
4
|
+
order to run scripts from any ruby file.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'replica_connect'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install replica_connect
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
To use the gem, include it in your ruby file as follows:
|
23
|
+
|
24
|
+
require 'replica_connect'
|
25
|
+
|
26
|
+
Then, create a connection with
|
27
|
+
|
28
|
+
connection = ReplicaConnect::Connection.new().connect
|
29
|
+
|
30
|
+
And run SQL queries with
|
31
|
+
|
32
|
+
connection.execute('SELECT * FROM users LIMIT 1')
|
33
|
+
|
34
|
+
The first time you run a script with replica_connect, it will prompt you
|
35
|
+
for database connection information.
|
36
|
+
|
37
|
+
replica_connect then creates a `rc_config.yml` file in the directory of your
|
38
|
+
script that contains the database connection information, so after you
|
39
|
+
input it once, you can change your script and run it multiple times
|
40
|
+
without re-inputting the connection data.
|
41
|
+
|
42
|
+
If you are checking your script into source control, make sure to add
|
43
|
+
the `rc_config.yml` file to your `.gitignore`
|
44
|
+
|
45
|
+
To delete the rc_config file, call:
|
46
|
+
|
47
|
+
`ReplicaConnect::Connection.new().clear_config`
|
48
|
+
|
49
|
+
If you are having problems, make sure you have the right adapter gem
|
50
|
+
installed for your database. As an example, for postgres, you need to
|
51
|
+
have the `pg` gem installed to connect to the database.
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
1. Fork it
|
56
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
58
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
59
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "replica_connect/version"
|
2
|
+
require 'active_record'
|
3
|
+
|
4
|
+
module ReplicaConnect
|
5
|
+
class Connection
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
if File.exists?('rc_config.yml')
|
9
|
+
file = YAML.load_file('rc_config.yml')
|
10
|
+
configs = file['rc']
|
11
|
+
@username = configs['username']
|
12
|
+
@password = configs['password']
|
13
|
+
@db_name = configs['db']
|
14
|
+
@host = configs['host']
|
15
|
+
@adapter = configs['adapter']
|
16
|
+
else
|
17
|
+
f = File.new('rc_config.yml', 'w+')
|
18
|
+
f.puts "rc:"
|
19
|
+
@username = get_from_user('username',f)
|
20
|
+
@password = get_from_user('password',f)
|
21
|
+
@db_name = get_from_user('db',f)
|
22
|
+
@host = get_from_user('host',f)
|
23
|
+
@adapter = get_from_user('adapter',f)
|
24
|
+
f.close
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def connect
|
29
|
+
ActiveRecord::Base.establish_connection(
|
30
|
+
:adapter => @adapter,
|
31
|
+
:host => @host,
|
32
|
+
:database => @db_name,
|
33
|
+
:username => @username,
|
34
|
+
:password => @password).connection
|
35
|
+
end
|
36
|
+
|
37
|
+
def clear_config
|
38
|
+
File.delete('rc_config.yml') unless !File.exists?('rc_config.yml')
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def get_from_user(param, file)
|
44
|
+
puts "Please enter your #{param}"
|
45
|
+
p = gets.chomp
|
46
|
+
file.puts " #{param}: #{p}"
|
47
|
+
p
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'replica_connect/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "replica_connect"
|
8
|
+
gem.version = ReplicaConnect::VERSION
|
9
|
+
gem.authors = ["Solomon Kahn", "Richard Boyle"]
|
10
|
+
gem.email = ["solomon.kahn@gmail.com"]
|
11
|
+
gem.description = "Connect to a database easily from a ruby file"
|
12
|
+
gem.summary = "Easily connect to a database in ruby scripts"
|
13
|
+
gem.homepage = "http://www.github.com/paperlesspost/replica_connect"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.add_dependency('activerecord')
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: replica_connect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Solomon Kahn
|
8
|
+
- Richard Boyle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
description: Connect to a database easily from a ruby file
|
29
|
+
email:
|
30
|
+
- solomon.kahn@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/replica_connect.rb
|
41
|
+
- lib/replica_connect/version.rb
|
42
|
+
- replica_connect.gemspec
|
43
|
+
homepage: http://www.github.com/paperlesspost/replica_connect
|
44
|
+
licenses: []
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.0.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Easily connect to a database in ruby scripts
|
66
|
+
test_files: []
|