moved ruby core class extensions to separate files

This commit is contained in:
2010-07-26 17:34:53 +03:00
parent 20429b3da8
commit 805ef21af4
5 changed files with 49 additions and 20 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -0,0 +1,8 @@
class Date
include Redistat::DateHelper
def to_time
Time.parse(self.to_s)
end
end

View File

@@ -0,0 +1,8 @@
class Fixnum
include Redistat::DateHelper
def to_time
Time.at(self)
end
end

View 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