redshift-rails 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 426219faba780ae7ff3ff5966dff5dc9260787c8
4
- data.tar.gz: 97339cc78b8c2dc94ae2319ad9399f1fc998b736
3
+ metadata.gz: 4f605674b0cf955d656884b736aab912821c54a6
4
+ data.tar.gz: 0398295b8ba3b00e8abb1a980ca3d52971b4ba59
5
5
  SHA512:
6
- metadata.gz: cf4fd7dacd0eb0214ac79b326b8cdd79b6b474b824f1dd74ef3eee221654bdf33e6ebf887fcedbd2374cb1536783b98ecb36e23d2e75d956bdc97d5a285698fa
7
- data.tar.gz: a003209fe8dc345467335df74d8476e08d352b63b9e0ee53bbb64f08dcfc7b3e31ae75a5c55ef1010a1864d6a0ef8758d6e02dd6fa4a575a1fe92040bb7737a3
6
+ metadata.gz: 223b29baa3675850303c8f33595b600ede517986d9cfc0f96ef7ca92e2cadc33afb9db56d90fdf3f6b24d391226bd03b1ff2fba471e92c2ce2ac111261002f0a
7
+ data.tar.gz: 3e8a04f951bc957eb751a6ccdcbd1c8a75c993147e9f00d0df00670348472e88ba2d71ae89bb38e124ab18781abd9c968eceb826b441d687a06375ca62b21dd9
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Redshift::Rails [![Gem Version](https://badge.fury.io/rb/redshift-rails.svg)](https://badge.fury.io/rb/redshift-rails)
2
2
 
3
- The library provides the railtie that allows redshift-client into Rails.
3
+ The library provides the railtie that allows redshift-client into Rails >= 4.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,34 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ Set your redshift url to `$REDSHIFT_URL`:
24
+
25
+ ```
26
+ $ export REDSHIFT_URL="redshift://user:password@*****.region.redshift.amazonaws.com:5439/dbname"
27
+ ```
28
+
29
+ or create `config/redshift.yml`:
30
+
31
+ ```yaml
32
+ # config/redshift.yml
33
+
34
+ development:
35
+ host: *****.region.redshift.amazonaws.com
36
+ port: 5439
37
+ user: user
38
+ password: password
39
+ dbname: dbname
40
+ ```
41
+
42
+ You can call `Redshift::Client` at anywhere.
43
+
44
+ ```ruby
45
+ class HealthController < ApplicationConttoller
46
+ def index
47
+ render json: Redshift::Client.connection.exec("SELECT NOW()").first
48
+ end
49
+ end
50
+ ```
24
51
 
25
52
  ## Development
26
53
 
@@ -32,6 +59,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
59
 
33
60
  Bug reports and pull requests are welcome on GitHub at https://github.com/dakatsuka/redshift-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
34
61
 
62
+ ## TODO
63
+
64
+ * Test
35
65
 
36
66
  ## License
37
67
 
@@ -0,0 +1,55 @@
1
+ require 'active_support/configurable'
2
+ require 'yaml'
3
+ require 'erb'
4
+ require 'uri'
5
+
6
+ module Redshift
7
+ module Rails
8
+ class << self
9
+ def config
10
+ Configuration.instance
11
+ end
12
+ end
13
+
14
+ class Configuration
15
+ include Singleton
16
+ include ActiveSupport::Configurable
17
+
18
+ config_accessor :host, :port, :user, :password, :dbname
19
+
20
+ def load!
21
+ resolve_config.each do |k, v|
22
+ send("#{k}=", v)
23
+ end
24
+ end
25
+
26
+ def database
27
+ {
28
+ host: host,
29
+ port: port,
30
+ user: user,
31
+ password: password,
32
+ dbname: dbname
33
+ }
34
+ end
35
+
36
+ private
37
+ def resolve_config
38
+ config_file = ::Rails.application.config.redshift.config_file
39
+
40
+ if File.exists?(config_file)
41
+ YAML.load(ERB.new(File.read(config_file)).result)[::Rails.env]
42
+ else
43
+ uri = URI.parse(ENV["REDSHIFT_URL"])
44
+ {
45
+ host: uri.host,
46
+ port: uri.port,
47
+ user: uri.user,
48
+ password: uri.password,
49
+ dbname: uri.path[1..-1]
50
+ }
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -3,11 +3,20 @@ module Redshift
3
3
  class Railtie < ::Rails::Railtie
4
4
  initializer "redshift_rails.initialize" do |app|
5
5
  ActiveSupport.on_load(:redshift_client_connection) do
6
- Redshift::Client.establish_connection
6
+ Redshift::Client.establish_connection Redshift::Rails.config.database
7
7
  end
8
8
 
9
9
  app.middleware.use Redshift::Rails::Middleware
10
10
  end
11
+
12
+ config.before_configuration do
13
+ config.redshift = ActiveSupport::OrderedOptions.new
14
+ config.redshift.config_file = "#{::Rails.root}/config/redshift.yml"
15
+ end
16
+
17
+ config.after_initialize do
18
+ Redshift::Rails.config.load!
19
+ end
11
20
  end
12
21
  end
13
22
  end
@@ -1,5 +1,5 @@
1
1
  module Redshift
2
2
  module Rails
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require "redshift/client"
2
2
  require "redshift/rails/version"
3
+ require "redshift/rails/configuration"
3
4
  require "redshift/rails/middleware"
4
5
  require "redshift/rails/railtie" if defined? Rails
5
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redshift-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dai Akatsuka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-10 00:00:00.000000000 Z
11
+ date: 2015-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redshift-client
@@ -98,6 +98,7 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - lib/redshift/rails.rb
101
+ - lib/redshift/rails/configuration.rb
101
102
  - lib/redshift/rails/middleware.rb
102
103
  - lib/redshift/rails/railtie.rb
103
104
  - lib/redshift/rails/version.rb