Module: Gxapi
- Defined in:
- lib/gxapi.rb,
lib/gxapi/base.rb,
lib/gxapi/engine.rb,
lib/gxapi/ostruct.rb,
lib/gxapi/version.rb,
lib/gxapi/google_analytics.rb,
lib/gxapi/controller_methods.rb,
lib/generators/gxapi/install_generator.rb
Defined Under Namespace
Modules: ControllerMethods Classes: Base, Engine, GoogleAnalytics, InstallGenerator, Ostruct
Constant Summary collapse
- VERSION =
'0.0.4'
Class Method Summary collapse
-
.cache ⇒ ActiveSupport::Cache::Store
get our cache instance.
-
.cache=(cache) ⇒ ActiveSupport::Cache::Store
setter for Gxapi.cache.
-
.cache_namespace ⇒ String?
namespace for our cache keys.
-
.cache_namespace=(val) ⇒ String
setter for Gxapi.cache_namespace.
-
.config ⇒ Gxapi::Ostruct
Gxapi config - this is loaded based on the Gxapi.config_path.
-
.config_path ⇒ String
get the config path for our config YAML file.
-
.config_path=(val) ⇒ String
setter for config path.
-
.env ⇒ String
our environment - defaults to Rails.env or test.
-
.env=(val) ⇒ String
Set the value of Gxapi.env.
-
.logger ⇒ Logger, Log4r::Logger
instance of logger for Gxapi.
-
.logger=(logger) ⇒ Logger, Log4r
Setter for the Logger.
-
.reload_experiments ⇒ Boolean
Reload all data from experiments.
-
.root ⇒ String
root directory for gxapi.
-
.with_error_handling(&block) ⇒ Value, false
Wrap with error handling logs errors and returns false if an error occurs.
Class Method Details
.cache ⇒ ActiveSupport::Cache::Store
get our cache instance
24 25 26 27 28 29 30 31 |
# File 'lib/gxapi.rb', line 24 def self.cache # if we have an overridden cache, return it return @overridden_cache if defined?(@overridden_cache) # use Rails.cache if it is defined return ::Rails.cache if defined?(::Rails) && ::Rails.cache # last resort, just use our own cache choice @cache ||= ActiveSupport::Cache::MemoryStore.new end |
.cache=(cache) ⇒ ActiveSupport::Cache::Store
setter for cache
37 38 39 |
# File 'lib/gxapi.rb', line 37 def self.cache=(cache) @overridden_cache = cache end |
.cache_namespace ⇒ String?
namespace for our cache keys
45 46 47 |
# File 'lib/gxapi.rb', line 45 def self.cache_namespace @cache_namespace end |
.cache_namespace=(val) ⇒ String
setter for cache_namespace
53 54 55 |
# File 'lib/gxapi.rb', line 53 def self.cache_namespace=(val) @cache_namespace = val end |
.config ⇒ Gxapi::Ostruct
Gxapi config - this is loaded based on the config_path
62 63 64 65 66 67 68 69 |
# File 'lib/gxapi.rb', line 62 def self.config @config ||= begin # parse our yml file after running it through ERB contents = File.read(self.config_path) yml = ERB.new(contents).result(binding) Gxapi::Ostruct.new(YAML.load(yml)[Gxapi.env]) end end |
.config_path ⇒ String
get the config path for our config YAML file
75 76 77 |
# File 'lib/gxapi.rb', line 75 def self.config_path @config_path ||= File.join(Rails.root, "config/gxapi.yml") end |
.config_path=(val) ⇒ String
setter for config path
83 84 85 |
# File 'lib/gxapi.rb', line 83 def self.config_path=(val) @config_path = val end |
.env ⇒ String
our environment - defaults to Rails.env or test
91 92 93 |
# File 'lib/gxapi.rb', line 91 def self.env @env ||= defined?(::Rails) ? ::Rails.env : "test" end |
.env=(val) ⇒ String
Set the value of env
99 100 101 |
# File 'lib/gxapi.rb', line 99 def self.env=(val) @env = val end |
.logger ⇒ Logger, Log4r::Logger
instance of logger for Gxapi
107 108 109 110 111 112 113 114 115 |
# File 'lib/gxapi.rb', line 107 def self.logger @logger ||= begin if defined?(::Rails) && ::Rails.logger ::Rails.logger else Logger.new(STDOUT) end end end |
.logger=(logger) ⇒ Logger, Log4r
Setter for the Logger
123 124 125 |
# File 'lib/gxapi.rb', line 123 def self.logger=(logger) @logger = logger end |
.reload_experiments ⇒ Boolean
Reload all data from experiments
131 132 133 134 |
# File 'lib/gxapi.rb', line 131 def self.reload_experiments Base.new("").reload_experiments true end |
.root ⇒ String
root directory for gxapi
141 142 143 |
# File 'lib/gxapi.rb', line 141 def self.root File.("../../", __FILE__) end |
.with_error_handling(&block) ⇒ Value, false
Wrap with error handling logs errors and returns false if an error occurs
151 152 153 154 155 156 157 158 159 |
# File 'lib/gxapi.rb', line 151 def self.with_error_handling(&block) begin yield rescue => e self.logger.error(e.) self.logger.error(e.backtrace) false end end |