fluidfeatures-rails 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/fluidfeatures/rails.rb
CHANGED
@@ -7,44 +7,57 @@ module FluidFeatures
|
|
7
7
|
attr_accessor :enabled
|
8
8
|
attr_accessor :ff_app
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
#
|
12
12
|
# This is called once, when your Rails application fires up.
|
13
13
|
# It sets up the before and after request hooks
|
14
14
|
#
|
15
15
|
def self.initializer
|
16
|
-
|
16
|
+
|
17
17
|
@enabled = false
|
18
|
-
#
|
19
|
-
# Without these FluidFeatures credentials we cannot talk to
|
20
|
-
# the FluidFeatures service.
|
21
|
-
#
|
22
|
-
#%w[FLUIDFEATURES_BASEURI FLUIDFEATURES_SECRET FLUIDFEATURES_APPID].each do |key|
|
23
|
-
# unless ENV[key]
|
24
|
-
# $stderr.puts "!! fluidfeatures-rails requires ENV[\"#{key}\"] (fluidfeatures is disabled)"
|
25
|
-
# return
|
26
|
-
# end
|
27
|
-
#end
|
28
|
-
unless defined? ::Rails
|
29
|
-
$stderr.puts "!! fluidfeatures-rails requires rails (fluidfeatures is disabled)"
|
30
|
-
return
|
31
|
-
end
|
32
|
-
$stderr.puts "=> fluidfeatures-rails initializing as app #{ENV["FLUIDFEATURES_APPID"]} with #{ENV["FLUIDFEATURES_BASEURI"]}"
|
33
18
|
|
19
|
+
# Initialize
|
34
20
|
::Rails::Application.initializer "fluidfeatures.initializer" do
|
35
21
|
ActiveSupport.on_load(:action_controller) do
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
22
|
+
|
23
|
+
# Without these FluidFeatures credentials we cannot talk to
|
24
|
+
# the FluidFeatures service.
|
25
|
+
is_configured = true
|
26
|
+
ff_config_path = "#{::Rails.root}/config/fluidfeatures.yml"
|
27
|
+
unless File.file? ff_config_path
|
28
|
+
%w[FLUIDFEATURES_BASEURI FLUIDFEATURES_SECRET FLUIDFEATURES_APPID].each do |key|
|
29
|
+
is_configured &= ENV[key]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
unless is_configured
|
33
|
+
$stderr.puts "fluidfeatures-rails is not configured. Run 'rails g fluidfeatures:config'"
|
34
|
+
break
|
35
|
+
end
|
36
|
+
|
37
|
+
if File.file? ff_config_path
|
38
|
+
config = ::FluidFeatures::Config.new(ff_config_path, ::Rails.env)
|
39
|
+
else
|
40
|
+
config = ::FluidFeatures::Config.new({
|
41
|
+
"base_uri" => ENV["FLUIDFEATURES_BASEURI"],
|
42
|
+
"app_id" => ENV["FLUIDFEATURES_APPID"],
|
43
|
+
"secret" => ENV["FLUIDFEATURES_SECRET"]
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
$stderr.puts "fluidfeatures-rails is configured with app_id '#{config["app_id"]}'. Run 'rails g fluidfeatures:config' to update config"
|
48
|
+
|
49
|
+
# create FF app store in global rails namespace
|
41
50
|
::FluidFeatures::Rails.ff_app = ::FluidFeatures.app(config)
|
51
|
+
|
52
|
+
# wrap each request in fluidfeatures user transaction
|
42
53
|
ActionController::Base.append_before_filter :fluidfeatures_request_before
|
43
54
|
ActionController::Base.append_after_filter :fluidfeatures_request_after
|
55
|
+
|
44
56
|
end
|
45
57
|
end
|
46
58
|
|
47
59
|
@enabled = true
|
60
|
+
|
48
61
|
end
|
49
62
|
|
50
63
|
end
|
@@ -163,7 +176,7 @@ module ActionController
|
|
163
176
|
# feature.
|
164
177
|
# This helps the FluidFeatures database prepopulate the feature set
|
165
178
|
# without requiring the developer to do it manually.
|
166
|
-
#
|
179
|
+
#
|
167
180
|
def fluidfeatures_request_after
|
168
181
|
ff_transaction.end_transaction
|
169
182
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Fluidfeatures
|
2
|
+
class ConfigGenerator < ::Rails::Generators::Base
|
3
|
+
|
4
|
+
CONFIG_FILE = "config/fluidfeatures.yml"
|
5
|
+
|
6
|
+
def create_initializer_file
|
7
|
+
|
8
|
+
puts "Enter FluidFeatures credentials [press enter to skip]"
|
9
|
+
print "development app_id: "
|
10
|
+
dev_app_id = gets.chomp
|
11
|
+
|
12
|
+
print "development secret: "
|
13
|
+
dev_secret = gets.chomp
|
14
|
+
|
15
|
+
print "production app_id: "
|
16
|
+
prod_app_id = gets.chomp
|
17
|
+
|
18
|
+
print "production secret: "
|
19
|
+
prod_secret = gets.chomp
|
20
|
+
|
21
|
+
print "test app_id: "
|
22
|
+
test_app_id = gets.chomp
|
23
|
+
|
24
|
+
print "test secret: "
|
25
|
+
test_secret = gets.chomp
|
26
|
+
|
27
|
+
puts "Warning: production app_id and secret have not been set in #{CONFIG_FILE}"
|
28
|
+
|
29
|
+
create_file CONFIG_FILE, """
|
30
|
+
common:
|
31
|
+
base_uri: https://www.fluidfeatures.com/service
|
32
|
+
cache:
|
33
|
+
enable: false
|
34
|
+
dir: tmp/fluidfeatures
|
35
|
+
limit: 2mb
|
36
|
+
|
37
|
+
development:
|
38
|
+
app_id: #{dev_app_id}
|
39
|
+
secret: #{dev_secret}
|
40
|
+
|
41
|
+
test:
|
42
|
+
app_id: #{test_app_id}
|
43
|
+
secret: #{test_secret}
|
44
|
+
|
45
|
+
production:
|
46
|
+
app_id: #{prod_app_id}
|
47
|
+
secret: #{prod_secret}
|
48
|
+
"""
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/initializer_spec.rb
CHANGED
@@ -10,7 +10,6 @@ describe "FluidFeatures Rails initialization" do
|
|
10
10
|
|
11
11
|
it "should start application if Rails defined" do
|
12
12
|
defined?(Rails).should be_true
|
13
|
-
$stderr.should_receive(:puts).with("=> fluidfeatures-rails initializing as app #{ENV["FLUIDFEATURES_APPID"]} with #{ENV["FLUIDFEATURES_BASEURI"]}")
|
14
13
|
FluidFeatures::Rails.initializer
|
15
14
|
FluidFeatures::Rails.enabled.should be_true
|
16
15
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluidfeatures-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluidfeatures
|
@@ -111,7 +111,7 @@ files:
|
|
111
111
|
- lib/fluidfeatures/rails/app/controllers/fluidfeatures_controller.rb
|
112
112
|
- lib/fluidfeatures/rails/config/routes.rb
|
113
113
|
- lib/fluidfeatures/rails/version.rb
|
114
|
-
- lib/generators/fluidfeatures/
|
114
|
+
- lib/generators/fluidfeatures/config_generator.rb
|
115
115
|
- lib/pre_ruby192/uri.rb
|
116
116
|
- spec/controller_extentions_spec.rb
|
117
117
|
- spec/controller_spec.rb
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module FluidFeatures
|
2
|
-
module Rails
|
3
|
-
module Generators
|
4
|
-
class InstallGenerator < ::Rails::Generators::Base
|
5
|
-
def create_initializer_file
|
6
|
-
create_file "config/fluidfeatures.yml", "common:
|
7
|
-
baseuri: https://www.fluidfeatures.com/service
|
8
|
-
cache:
|
9
|
-
enable: false
|
10
|
-
dir: tmp/fluidfeatures
|
11
|
-
limit: 2mb
|
12
|
-
|
13
|
-
development:
|
14
|
-
appid:
|
15
|
-
secret:
|
16
|
-
|
17
|
-
test:
|
18
|
-
appid:
|
19
|
-
secret:
|
20
|
-
|
21
|
-
production:
|
22
|
-
appid:
|
23
|
-
secret:
|
24
|
-
"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|