dohutil 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,15 +2,13 @@ require 'date'
2
2
  require 'time'
3
3
 
4
4
  class DateTime
5
- DOHRUBY_SECONDS_IN_DAY = (24 * 60 * 60).freeze
6
-
7
5
  def self.zow
8
6
  obj = now
9
7
  new(obj.year, obj.month, obj.mday, obj.hour, obj.min, obj.sec, 0)
10
8
  end
11
9
 
12
10
  def self.seconds_to_days(seconds)
13
- seconds.to_f / DOHRUBY_SECONDS_IN_DAY.to_f
11
+ seconds.to_f * SECONDS_IN_DAY #.to_f
14
12
  end
15
13
 
16
14
  def next_second(n = 1)
@@ -23,7 +21,7 @@ class DateTime
23
21
 
24
22
  # subtract another DateTime object, return difference in seconds
25
23
  def sub_dt(other)
26
- ((self - other) * DOHRUBY_SECONDS_IN_DAY).to_i
24
+ ((self - other) / SECONDS_IN_DAY).to_i
27
25
  end
28
26
  end
29
27
 
@@ -2,24 +2,28 @@ require 'date'
2
2
  require 'bigdecimal'
3
3
 
4
4
  class Date
5
+ undef inspect
5
6
  def inspect
6
7
  "#<Date:#{strftime('%F')}>"
7
8
  end
8
9
  end
9
10
 
10
11
  class DateTime
12
+ undef inspect
11
13
  def inspect
12
14
  "#<DateTime:#{strftime('%F %X %z')}>"
13
15
  end
14
16
  end
15
17
 
16
18
  class Time
19
+ undef inspect
17
20
  def inspect
18
21
  "#<Time:#{strftime('%F %X %z')}>"
19
22
  end
20
23
  end
21
24
 
22
25
  class BigDecimal
26
+ undef inspect
23
27
  def inspect
24
28
  "#<BigDecimal:#{to_s('F')}>"
25
29
  end
@@ -2,7 +2,7 @@ class String
2
2
  def firstn(limit)
3
3
  return nil if limit < 0
4
4
  return '' if limit == 0
5
- slice(Range.new(0, limit -1))
5
+ slice(Range.new(0, limit - 1))
6
6
  end
7
7
 
8
8
  def lastn(limit)
@@ -2,38 +2,36 @@ require 'doh/core_ext/datewithtime'
2
2
 
3
3
  module Doh
4
4
 
5
- @@current_date_objs = []
5
+ @current_date_stack = []
6
6
 
7
7
  def self.current_date(dflt = Date.today)
8
- return dflt if @@current_date_objs.empty?
9
- @@current_date_objs.last.to_date
8
+ return dflt if @current_date_stack.empty?
9
+ @current_date_stack.last.to_date
10
10
  end
11
11
 
12
12
  def self.current_datetime(dflt = DateTime.zow)
13
- return dflt if @@current_date_objs.empty?
14
- cdo = @@current_date_objs.last
13
+ return dflt if @current_date_stack.empty?
14
+ cdo = @current_date_stack.last
15
15
  return cdo if cdo.respond_to?(:hour)
16
16
  DateTime.new(cdo.year, cdo.month, cdo.day, dflt.hour, dflt.min, dflt.sec, dflt.zone)
17
17
  end
18
18
 
19
19
  def self.push_current_date(date_obj)
20
- @@current_date_objs.push(date_obj)
20
+ @current_date_stack.push(date_obj)
21
21
  end
22
22
 
23
23
  def self.pop_current_date
24
- @@current_date_objs.pop
24
+ @current_date_stack.pop
25
25
  end
26
26
 
27
27
  def self.clear_current_date
28
- @@current_date_objs.clear
28
+ @current_date_stack.clear
29
29
  end
30
30
 
31
- def self.date_as(date_obj, &block)
31
+ def self.date_as(date_obj)
32
32
  push_current_date(date_obj)
33
33
  begin
34
- retval = block.call
35
- rescue
36
- raise
34
+ retval = yield
37
35
  ensure
38
36
  pop_current_date
39
37
  end
data/lib/doh/log/stub.rb CHANGED
@@ -1,14 +1,25 @@
1
- class Object
1
+ module DohLog
2
+ class StubInterface
3
+ def self.debug(msg); end
4
+ def self.info(msg); end
5
+ def self.warn(msg); end
6
+ def self.error(msg, exception = nil); end
7
+ def self.fatal(msg, exception = nil); end
8
+ end
9
+ end
10
+
11
+ class Module
2
12
  unless method_defined?(:dohlog)
3
- class DohlogStubInterface
4
- def self.debug(msg); end
5
- def self.info(msg); end
6
- def self.warn(msg); end
7
- def self.error(msg, exception = nil); end
8
- def self.fatal(msg, exception = nil); end
13
+ def dohlog
14
+ DohLog::StubInterface
9
15
  end
16
+ end
17
+ end
18
+
19
+ class Object
20
+ unless method_defined?(:dohlog)
10
21
  def dohlog
11
- DohlogStubInterface
22
+ DohLog::StubInterface
12
23
  end
13
24
  end
14
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dohutil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-30 00:00:00.000000000Z
13
+ date: 2012-04-03 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: dohroot
17
- requirement: &70168643920460 !ruby/object:Gem::Requirement
17
+ requirement: &70119051021380 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.1.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70168643920460
25
+ version_requirements: *70119051021380
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: dohtest
28
- requirement: &70168643919780 !ruby/object:Gem::Requirement
28
+ requirement: &70119051020660 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 0.1.8
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *70168643919780
36
+ version_requirements: *70119051020660
37
37
  description: Tiny utilities, packaged together so they don't each have their own gem.
38
38
  email:
39
39
  - devinfo@atpsoft.com