Module: FluidFeatures::Rails

Defined in:
lib/fluidfeatures/rails.rb,
lib/fluidfeatures/rails/version.rb

Constant Summary collapse

VERSION =
'0.6.3'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.enabledObject

Returns the value of attribute enabled.



7
8
9
# File 'lib/fluidfeatures/rails.rb', line 7

def enabled
  @enabled
end

.ff_appObject

Returns the value of attribute ff_app.



8
9
10
# File 'lib/fluidfeatures/rails.rb', line 8

def ff_app
  @ff_app
end

Class Method Details

.initializerObject

This is called once, when your Rails application fires up. It sets up the before and after request hooks



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fluidfeatures/rails.rb', line 15

def self.initializer

  @enabled = false

  # Initialize
  ::Rails::Application.initializer "fluidfeatures.initializer" do
    ActiveSupport.on_load(:action_controller) do

      # Without these FluidFeatures credentials we cannot talk to
      # the FluidFeatures service.
      is_configured = true
      ff_config_path = "#{::Rails.root}/config/fluidfeatures.yml"
      unless File.file? ff_config_path
        %w[FLUIDFEATURES_BASEURI FLUIDFEATURES_SECRET FLUIDFEATURES_APPID].each do |key|
          is_configured &= ENV[key]
        end
      end
      unless is_configured
        $stderr.puts "fluidfeatures-rails is not configured. Run 'rails g fluidfeatures:config'"
        break
      end

      if File.file? ff_config_path
        config = ::FluidFeatures::Config.new(ff_config_path, ::Rails.env)
      else
        config = ::FluidFeatures::Config.new({
          "base_uri" => ENV["FLUIDFEATURES_BASEURI"],
          "app_id"   => ENV["FLUIDFEATURES_APPID"],
          "secret"   => ENV["FLUIDFEATURES_SECRET"]
        })
      end

      $stderr.puts "fluidfeatures-rails is configured with app_id '#{config["app_id"]}'. Run 'rails g fluidfeatures:config' to update config"

      # create FF app store in global rails namespace
      ::FluidFeatures::Rails.ff_app = ::FluidFeatures.app(config)

      # wrap each request in fluidfeatures user transaction
      ActionController::Base.append_before_filter :fluidfeatures_request_before
      ActionController::Base.append_after_filter  :fluidfeatures_request_after

    end
  end

  @enabled = true

end