tworgy-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tworgy/dbc.rb ADDED
@@ -0,0 +1,35 @@
1
+ class DBC
2
+ def self.require(condition, message = "")
3
+ unless condition
4
+ error('Pre', message, caller)
5
+ end
6
+ end
7
+
8
+ def self.require_not_blank(string, message = "")
9
+ if string.strip.blank?
10
+ error('Pre', message, caller)
11
+ end
12
+ end
13
+
14
+ def self.assert(condition, message = "")
15
+ unless condition
16
+ error('Assert', message, caller)
17
+ end
18
+ end
19
+
20
+ def self.ensure(condition, message = "")
21
+ unless condition
22
+ error('Post', message, caller)
23
+ end
24
+ end
25
+
26
+ def self.fail(message = "")
27
+ error('Fail', message, caller)
28
+ end
29
+
30
+ private
31
+
32
+ def self.error(type, message, caller)
33
+ raise RuntimeError.new("#{type}-condition failed: #{message}\nTrace was: #{caller.join("\n")}")
34
+ end
35
+ end
@@ -8,6 +8,20 @@ class String
8
8
  def /(str_to_join)
9
9
  File.join(self, str_to_join)
10
10
  end
11
+
12
+ def self.unique_append(options)
13
+ root = options[:root]
14
+ append = options[:append]
15
+ join = options[:join]
16
+
17
+ if root.blank?
18
+ append
19
+ elsif append.blank? || root.include?(append)
20
+ root
21
+ else
22
+ "#{root}#{join} #{append}"
23
+ end
24
+ end
11
25
  end
12
26
 
13
27
  class Time
data/lib/tworgy-ruby.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'tworgy/recursively'
2
2
  require 'tworgy/standard_extensions'
3
3
  require 'tworgy/tmail'
4
+ require 'tworgy/dbc'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tworgy-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Holroyd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-02 00:00:00 +11:00
12
+ date: 2009-11-06 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -36,6 +36,7 @@ files:
36
36
  - README.rdoc
37
37
  - Rakefile
38
38
  - lib/tworgy-ruby.rb
39
+ - lib/tworgy/dbc.rb
39
40
  - lib/tworgy/recursively.rb
40
41
  - lib/tworgy/standard_extensions.rb
41
42
  - lib/tworgy/tmail.rb