lingohub_utils 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Helmut Juskewycz
1
+ Copyright (c) 2012 lingohub GmbH
2
2
 
3
3
  MIT License
4
4
 
@@ -0,0 +1,11 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Array
4
+
5
+ # Raises an ArgumentError if the array is empty (contains no items at all, nil objects count as item).
6
+ # @param message [String] optional parameter that is the error message
7
+ def raise_if_empty(message = "Array must not be empty.")
8
+ raise ArgumentError.new(message) if self.empty?
9
+ end
10
+
11
+ end
@@ -1,3 +1,3 @@
1
1
  module LingohubUtils
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -0,0 +1,25 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ require "spec_helper"
4
+
5
+ describe Array do
6
+
7
+ describe "#raise_if_empty" do
8
+ context "not empty" do
9
+ it "should not raise ArgumentError" do
10
+ lambda { ["asdf", 1].raise_if_empty }.should_not raise_error ArgumentError
11
+ end
12
+
13
+ it "should not raise ArgumentError when nil item is in Array" do
14
+ lambda { [nil].raise_if_empty }.should_not raise_error ArgumentError
15
+ end
16
+ end
17
+
18
+ context "empty" do
19
+ it "should not raise ArgumentError" do
20
+ lambda { [].raise_if_empty }.should raise_error ArgumentError
21
+ end
22
+ end
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lingohub_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,6 +24,7 @@ files:
24
24
  - LICENSE
25
25
  - README.md
26
26
  - Rakefile
27
+ - lib/lh/core_extensions/array/raise_if_empty.rb
27
28
  - lib/lh/core_extensions/array/raise_if_item_nil.rb
28
29
  - lib/lh/core_extensions/array/to_h.rb
29
30
  - lib/lh/core_extensions/hash/raise_if_value_nil.rb
@@ -33,6 +34,7 @@ files:
33
34
  - lib/lingohub_utils.rb
34
35
  - lib/lingohub_utils/version.rb
35
36
  - lingohub_utils.gemspec
37
+ - spec/lh/core_extensions/array/raise_if_empty_spec.rb
36
38
  - spec/lh/core_extensions/array/raise_if_item_nil_spec.rb
37
39
  - spec/lh/core_extensions/array/to_h_spec.rb
38
40
  - spec/lh/core_extensions/hash/raise_if_value_nil_spec.rb
@@ -65,6 +67,7 @@ specification_version: 3
65
67
  summary: This gem contains general util classes and extensions used by other lingohub
66
68
  gems and programms.
67
69
  test_files:
70
+ - spec/lh/core_extensions/array/raise_if_empty_spec.rb
68
71
  - spec/lh/core_extensions/array/raise_if_item_nil_spec.rb
69
72
  - spec/lh/core_extensions/array/to_h_spec.rb
70
73
  - spec/lh/core_extensions/hash/raise_if_value_nil_spec.rb