Module: Prisma
- Defined in:
- lib/prisma.rb,
lib/prisma/group.rb,
lib/prisma/filter.rb,
lib/prisma/server.rb,
lib/prisma/railtie.rb,
lib/prisma/null_logger.rb
Overview
Used for configuration, typically in a Rails initializer.
Defined Under Namespace
Modules: Filter Classes: Group, NullLogger, Railtie, Server
Class Method Summary collapse
-
.group(name, options = {}, &block) ⇒ Object
Configures a group.
-
.redis ⇒ Redis::Namespace
Returns a default or configured
Redis
instance wrapped in aRedis::Namespace
. -
.setup {|_self| ... } ⇒ Object
Configure prisma.
Instance Method Summary collapse
-
#logger ⇒ Object
Logger instance responding to
debug
,warn
anderror
. -
#redis ⇒ Object
Set your own
Redis
instance, it will be wrapped into aRedis::Namespace
object with the configured namespace. -
#redis_expiration_duration ⇒ Object
Duration in seconds for expiring redis keys (easy to use with Rails duration helpers
1.day
). -
#redis_namespace ⇒ Object
String for redis namespace, defaults to
prisma
.
Class Method Details
.group(name, options = {}, &block) ⇒ Object
Configures a group. The instance of the current ActionController is being passed as an argument into the block. As an example, tracking daily active users could be as simple as:
Prisma.setup do |config|
config.group :logged_in { |controller| controller.current_user.id }
end
65 66 67 |
# File 'lib/prisma.rb', line 65 def self.group(name, ={}, &block) @@groups[name] = Group.new(.merge(name: name, block: block)) end |
.redis ⇒ Redis::Namespace
Returns a default or configured Redis
instance wrapped in a Redis::Namespace
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/prisma.rb', line 71 def self.redis @@namespaced_redis ||= lambda do case @@redis when String if @@redis =~ /redis\:\/\// redis = Redis.connect(url: @@redis, thread_safe: true) else host, port, db = @@redis.split(':') redis = Redis.new(host: host, port: port, thread_safe: true, db: db) end Redis::Namespace.new(redis_namespace, redis: redis) else Redis::Namespace.new(redis_namespace, redis: @@redis) end end.call end |
.setup {|_self| ... } ⇒ Object
Configure prisma. Example usage:
Prisma.setup do |config|
config.group :active_api_clients { |controller| controller.current_client.id }
config.redis = Redis.new(db: 1)
config.redis_namespace = 'stats'
config.redis_expiration_duration = 2.days
config.logger = Rails.logger
end
51 52 53 54 |
# File 'lib/prisma.rb', line 51 def self.setup yield self store_configuration end |
Instance Method Details
#logger ⇒ Object
Logger instance responding to debug
, warn
and error
.
35 |
# File 'lib/prisma.rb', line 35 mattr_accessor :logger |
#redis ⇒ Object
Set your own Redis
instance, it will be wrapped into a Redis::Namespace
object with the configured namespace. Useful for when Redis is not available on the standard IP and port. Allows:
-
hostname:port
-
hostname:port:db
-
redis://hostname:port/db
-
Redis
instance
23 |
# File 'lib/prisma.rb', line 23 mattr_accessor :redis |
#redis_expiration_duration ⇒ Object
Duration in seconds for expiring redis keys (easy to use with Rails duration helpers 1.day
)
41 |
# File 'lib/prisma.rb', line 41 mattr_accessor :redis_expiration_duration |
#redis_namespace ⇒ Object
String for redis namespace, defaults to prisma
29 |
# File 'lib/prisma.rb', line 29 mattr_accessor :redis_namespace |