Module: Pushr::Core

Defined in:
lib/pushr/core.rb

Constant Summary collapse

NAME =
'Pushr'
DEFAULTS =
{ external_id_tag: 'external_id' }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



16
17
18
# File 'lib/pushr/core.rb', line 16

def options=(value)
  @options = value
end

Class Method Details

.configuration_fileObject



57
58
59
# File 'lib/pushr/core.rb', line 57

def self.configuration_file
  options[:configuration_file]
end

.configuration_file=(filename) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/pushr/core.rb', line 61

def self.configuration_file=(filename)
  if filename
    filename = File.join(Dir.pwd, filename) unless Pathname.new(filename).absolute?
    if File.file?(filename)
      options[:configuration_file] = filename
    else
      fail ArgumentError, "can not find config file: #{filename}"
    end
  end
end

.configure {|_self| ... } ⇒ Object

Configuration for Pushr, use like:

Pushr::Core.configure do |config|
  config.redis = { namespace: 'myapp', url: 'redis://myhost:8877/mydb' }
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Pushr::Core)

    the object that the method was called on



28
29
30
# File 'lib/pushr/core.rb', line 28

def self.configure
  yield self
end

.external_id_tagObject



53
54
55
# File 'lib/pushr/core.rb', line 53

def self.external_id_tag
  options[:external_id_tag]
end

.external_id_tag=(value) ⇒ Object



49
50
51
# File 'lib/pushr/core.rb', line 49

def self.external_id_tag=(value)
  options[:external_id_tag] = value
end

.instrument(name, payload = {}) ⇒ Object

instruments with a block



73
74
75
76
77
# File 'lib/pushr/core.rb', line 73

def self.instrument(name, payload = {})
  ActiveSupport::Notifications.instrument(name, payload) do
    yield
  end
end

.optionsObject



18
19
20
# File 'lib/pushr/core.rb', line 18

def self.options
  @options ||= DEFAULTS.dup
end

.redis(&block) ⇒ Object



32
33
34
35
36
# File 'lib/pushr/core.rb', line 32

def self.redis(&block)
  fail ArgumentError, 'requires a block' unless block
  @redis ||= Pushr::RedisConnection.create
  @redis.with(&block)
end

.redis=(hash) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/pushr/core.rb', line 38

def self.redis=(hash)
  if hash.is_a?(Hash)
    options.merge!(hash)
    @redis = RedisConnection.create(options)
  elsif hash.is_a?(ConnectionPool)
    @redis = hash
  else
    fail ArgumentError, 'redis= requires a Hash or ConnectionPool'
  end
end