Module: Timely

Defined in:
lib/timely.rb,
lib/timely/cell.rb

Defined Under Namespace

Modules: Formats, Rows Classes: Cell, Column, ConfigurationError, Engine, Formatter, Report, Row

Constant Summary collapse

PERIODS =
%w( year quarter month week day hour )
@@default_precision =
2
@@date_formats =
{
  year: "%Y",
  quarter: "%b %Y",
  month: "%b %Y",
  week: "%-1d %b",
  day: "%-1d %b",
  hour: "%-1I %p (%m/%-1d)"
}
@@default_lengths =
{
  year: 3,
  quarter: 6,
  month: 6,
  week: 5,
  day: 7,
  hour: 8
}
@@redis =
nil
@@cache_separator =
":"

Class Method Summary collapse

Class Method Details

.periodsObject



76
77
78
# File 'lib/timely.rb', line 76

def self.periods
  PERIODS
end

.redisObject

Returns the current Redis connection. If none has been created, will create a new one.



103
104
105
106
107
# File 'lib/timely.rb', line 103

def self.redis
  return @redis if @redis
  self.redis = Redis.respond_to?(:connect) ? Redis.connect : "localhost:6379"
  self.redis
end

.redis=(server) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/timely.rb', line 80

def self.redis=(server)
  case server
  when String
    if server =~ /redis\:\/\//
      redis = Redis.connect(url: server, thread_safe: true)
    else
      server, namespace = server.split('/', 2)
      host, port, db = server.split(':')
      redis = Redis.new(host: host, port: port,
        thread_safe: true, db: db)
    end
    namespace ||= :timely

    @redis = Redis::Namespace.new(namespace, :redis => redis)
  when Redis::Namespace
    @redis = server
  else
    @redis = Redis::Namespace.new(:timely, :redis => server)
  end
end

.setup {|_self| ... } ⇒ Object

Access the configuration in an initializer like:

Timely.setup do |config|
  config.redis = ...
end

Yields:

  • (_self)

Yield Parameters:

  • _self (Timely)

    the object that the method was called on



72
73
74
# File 'lib/timely.rb', line 72

def self.setup
  yield self
end