c12-commons 0.0.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.project +11 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/c12-commons.gemspec +23 -0
- data/lib/c12-commons/ruby.rb +18 -0
- data/lib/c12-commons/version.rb +6 -0
- data/lib/c12-commons.rb +4 -0
- data/spec/c12-commons/ruby_spec.rb +32 -0
- data/spec/spec_helper.rb +19 -0
- metadata +79 -0
data/.gitignore
ADDED
data/.project
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/c12-commons.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "c12-commons/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "c12-commons"
|
7
|
+
s.version = C12::Commons::VERSION
|
8
|
+
s.authors = ["Dimitri Kurashvili"]
|
9
|
+
s.email = ["dimitri@c12.ge"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Common functions}
|
12
|
+
s.description = %q{Common functionality for Ruby code}
|
13
|
+
|
14
|
+
s.rubyforge_project = "c12-commons"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency 'rspec', '~> 2'
|
22
|
+
s.add_development_dependency 'simplecov'
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
# Returns the first argument unless it's <code>nil</code>,
|
4
|
+
# then the second argument is returned.
|
5
|
+
def nvl(value, value_if_nil = 0)
|
6
|
+
value.nil? ? value_if_nil : value
|
7
|
+
end
|
8
|
+
|
9
|
+
# <code>nil</code> is empty, <code>''</code> is empty,
|
10
|
+
# empty <code>Array</code> or <code>Array</code> of <code>nil</code>s is empty.
|
11
|
+
# Other classes are teseted on response to <code>:empty?</code>.
|
12
|
+
def empty?(value)
|
13
|
+
return true if value.nil?
|
14
|
+
return value.strip.empty? if value.instance_of? String
|
15
|
+
return value.compact.empty? if value.instance_of? Array
|
16
|
+
return value.empty? if value.respond_to? :empty?
|
17
|
+
false
|
18
|
+
end
|
data/lib/c12-commons.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'c12-commons'
|
4
|
+
|
5
|
+
# გადაეცით ორი არგუმენტი და შეადარეთ გამოსავალი.
|
6
|
+
def test_nvl(a1, a2, expect)
|
7
|
+
describe "nvl(#{a1.inspect}, #{a2.inspect})" do
|
8
|
+
subject { nvl(a1, a2) }
|
9
|
+
it("should be #{expect.inspect}") { should == expect }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
test_nvl(nil, 0, 0)
|
14
|
+
test_nvl(nil, 1, 1)
|
15
|
+
test_nvl(nil, 2, 2)
|
16
|
+
|
17
|
+
def test_emptiness(val, is_empty)
|
18
|
+
describe "#{val.inspect}" do
|
19
|
+
subject { empty?(val) }
|
20
|
+
it("is #{is_empty ? '' : ' not '} empty") { should == is_empty }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
test_emptiness(nil, true)
|
25
|
+
test_emptiness('', true)
|
26
|
+
test_emptiness([], true)
|
27
|
+
test_emptiness({}, true)
|
28
|
+
test_emptiness([nil], true)
|
29
|
+
test_emptiness(1, false)
|
30
|
+
test_emptiness('texts', false)
|
31
|
+
test_emptiness([1, 2, 3], false)
|
32
|
+
test_emptiness({:a => 1, :b=>2}, false)
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
require 'c12-commons'
|
4
|
+
|
5
|
+
# SimpleCov
|
6
|
+
|
7
|
+
require 'simplecov'
|
8
|
+
|
9
|
+
SimpleCov.start do
|
10
|
+
add_filter '/spec/'
|
11
|
+
end
|
12
|
+
|
13
|
+
# RSpec
|
14
|
+
|
15
|
+
require 'rspec'
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.include(RSpec::Matchers)
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: c12-commons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.beta1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dimitri Kurashvili
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &80797510 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *80797510
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: simplecov
|
27
|
+
requirement: &80796540 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *80796540
|
36
|
+
description: Common functionality for Ruby code
|
37
|
+
email:
|
38
|
+
- dimitri@c12.ge
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .project
|
45
|
+
- .rspec
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- c12-commons.gemspec
|
49
|
+
- lib/c12-commons.rb
|
50
|
+
- lib/c12-commons/ruby.rb
|
51
|
+
- lib/c12-commons/version.rb
|
52
|
+
- spec/c12-commons/ruby_spec.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: ''
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>'
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.3.1
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: c12-commons
|
74
|
+
rubygems_version: 1.8.13
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Common functions
|
78
|
+
test_files: []
|
79
|
+
has_rdoc:
|