mirror of
https://github.com/jimeh/redistat.git
synced 2026-02-19 13:26:39 +00:00
moved ruby core class extensions to separate files
This commit is contained in:
@@ -8,6 +8,9 @@ require "digest/sha1"
|
||||
require "redistat/database"
|
||||
require "redistat/date"
|
||||
require "redistat/event"
|
||||
require "redistat/extensions/date"
|
||||
require "redistat/extensions/time"
|
||||
require "redistat/extensions/fixnum"
|
||||
require "redistat/key"
|
||||
require "redistat/label"
|
||||
require "redistat/model"
|
||||
|
||||
@@ -87,25 +87,6 @@ module Redistat
|
||||
def to_redistat
|
||||
Redistat::Date.new(self)
|
||||
end
|
||||
alias :to_rs :to_redistat
|
||||
alias :to_rs :to_redistat
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Date
|
||||
include Redistat::DateHelper
|
||||
def to_time
|
||||
Time.parse(self.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
class Time
|
||||
include Redistat::DateHelper
|
||||
end
|
||||
|
||||
class Fixnum
|
||||
include Redistat::DateHelper
|
||||
def to_time
|
||||
Time.at(self)
|
||||
end
|
||||
end
|
||||
8
lib/redistat/extensions/date.rb
Normal file
8
lib/redistat/extensions/date.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Date
|
||||
include Redistat::DateHelper
|
||||
|
||||
def to_time
|
||||
Time.parse(self.to_s)
|
||||
end
|
||||
|
||||
end
|
||||
8
lib/redistat/extensions/fixnum.rb
Normal file
8
lib/redistat/extensions/fixnum.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Fixnum
|
||||
include Redistat::DateHelper
|
||||
|
||||
def to_time
|
||||
Time.at(self)
|
||||
end
|
||||
|
||||
end
|
||||
29
lib/redistat/extensions/time.rb
Normal file
29
lib/redistat/extensions/time.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class Time
|
||||
include Redistat::DateHelper
|
||||
|
||||
# %w[ round floor ceil ].each do |_method|
|
||||
# define_method _method do |*args|
|
||||
# seconds = args.first || 60
|
||||
# Time.at((self.to_f / seconds).send(_method) * seconds)
|
||||
# end
|
||||
# end
|
||||
|
||||
DEPTHS = [:year, :month, :day, :hour, :min, :sec, :usec]
|
||||
|
||||
def floor(unit, multiple = nil)
|
||||
multiple ||= 1
|
||||
new_time = []
|
||||
DEPTHS.each_with_index do |depth, i|
|
||||
index = DEPTHS.index(unit)
|
||||
if i < index
|
||||
new_time << self.send(depth)
|
||||
elsif i > index
|
||||
new_time << 0
|
||||
else
|
||||
new_time << self.send(depth)
|
||||
end
|
||||
end
|
||||
Time.utc(*new_time)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user