rego-ruby-ext 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +20 -0
- data/README.md +23 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/init.rb +2 -0
- data/lib/date.rb +4 -0
- data/lib/enumerable.rb +31 -0
- data/lib/nil.rb +15 -0
- data/lib/numeric.rb +5 -0
- data/lib/rego-ruby-ext.rb +4 -0
- data/lib/string-interpolation.rb +50 -0
- data/lib/string.rb +26 -0
- data/lib/symbol.rb +3 -0
- data/lib/time.rb +4 -0
- data/rego-ruby-ext.gemspec +79 -0
- data/spec/date_spec.rb +7 -0
- data/spec/enumerable_spec.rb +51 -0
- data/spec/nil_spec.rb +17 -0
- data/spec/numeric_spec.rb +7 -0
- data/spec/rego-ruby-ext_spec.rb +5 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/string_interpolation_spec.rb +31 -0
- data/spec/string_spec.rb +21 -0
- data/spec/symbol_spec.rb +8 -0
- data/spec/time_spec.rb +7 -0
- metadata +170 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rdoc"
|
10
|
+
gem "rspec", "~> 2.3.0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Alex Tkachev
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# rego-ruby-ext
|
2
|
+
|
3
|
+
Ruby core extensions that are common for all ReGO projects
|
4
|
+
|
5
|
+
# Release notes
|
6
|
+
|
7
|
+
* 0.1.0 - first release
|
8
|
+
|
9
|
+
# Contributing to rego-ruby-ext
|
10
|
+
|
11
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
12
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
13
|
+
* Fork the project
|
14
|
+
* Start a feature/bugfix branch
|
15
|
+
* Commit and push until you are happy with your contribution
|
16
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
17
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
18
|
+
|
19
|
+
# Copyright
|
20
|
+
|
21
|
+
Copyright (c) 2011 Alex Tkachev. See LICENSE.txt for
|
22
|
+
further details.
|
23
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "rego-ruby-ext"
|
18
|
+
gem.homepage = "http://github.com/alextk/rego-ruby-ext"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Some basic ruby core classes extensions with tests}
|
21
|
+
gem.description = %Q{Ruby core extensions that are common for all ReGO projects}
|
22
|
+
gem.email = "tkachev.alex@gmail.com"
|
23
|
+
gem.authors = ["Alex Tkachev"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
RDoc::Task.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "rego-ruby-ext #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/init.rb
ADDED
data/lib/date.rb
ADDED
data/lib/enumerable.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Enumerable
|
2
|
+
|
3
|
+
# Add dynamic attribute-based selectors.
|
4
|
+
# Ex:
|
5
|
+
# [{:name=>'Guy',:last_name=>'Shmuely'},
|
6
|
+
# {:name=>'Jack',:last_name=>'Sperow'}].find_by_name_and_last_name('Guy','Shmuely')
|
7
|
+
# => [{:name=>'Guy',:last_name=>'Shmuely'}]
|
8
|
+
# [{:name=>'Guy',:last_name=>'Shmuely',:age=>25},
|
9
|
+
# {:name=>'Jack',:last_name=>'Sperow'},
|
10
|
+
# {:name=>'Roobin'}].collect_name_and_last_name
|
11
|
+
# => [['Guy','Shmuely'],['Jack','Sperow'],['Roobin',nil]]
|
12
|
+
def method_missing(method_id, *arguments)
|
13
|
+
if match = /collect_([_a-zA-Z]\w*)/.match(method_id.to_s)
|
14
|
+
attributes = match.captures.last.split('_and_')
|
15
|
+
collection = self.collect{|array| attributes.collect{|attr| (array.is_a?(Array) || array.is_a?(Hash)) ? array[attr.to_sym] : array.send(attr.to_sym)}}
|
16
|
+
collection.flatten! if attributes.size == 1
|
17
|
+
collection
|
18
|
+
elsif match = /select_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
|
19
|
+
attribute_names = match.captures.last.split('_and_')
|
20
|
+
select do |element|
|
21
|
+
flag=true
|
22
|
+
attribute_names.each_with_index { |name, idx| value=(element.is_a?(Array) || element.is_a?(Hash)) ? element[name.to_sym] : element.send(name)
|
23
|
+
flag=false unless value==arguments[idx] }
|
24
|
+
flag
|
25
|
+
end
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/nil.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Adds several instance methods to NilClass.
|
2
|
+
class NilClass
|
3
|
+
# Ex: nil.empty? => true
|
4
|
+
def empty?; true; end
|
5
|
+
def blank?; true; end
|
6
|
+
|
7
|
+
def any?; false; end
|
8
|
+
def include?(*args); false; end
|
9
|
+
|
10
|
+
def strip; nil; end
|
11
|
+
def truncate; nil; end
|
12
|
+
|
13
|
+
#DO NOT override to_sym this since it breaks globalize
|
14
|
+
#def to_sym; ""; end
|
15
|
+
end
|
data/lib/numeric.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# heavily based on Masao Mutoh's gettext String interpolation extension
|
2
|
+
# http://github.com/mutoh/gettext/blob/f6566738b981fe0952548c421042ad1e0cdfb31e/lib/gettext/core_ext/string.rb
|
3
|
+
|
4
|
+
module StringInterpolation
|
5
|
+
INTERPOLATION_PATTERN = Regexp.union(
|
6
|
+
/%%/,
|
7
|
+
/%\{(\w+)\}/, # matches placeholders like "%{foo}"
|
8
|
+
/%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
|
9
|
+
)
|
10
|
+
|
11
|
+
# define module methods (static methods, equivalent of writing def self.interpolate ... end)
|
12
|
+
class << self
|
13
|
+
|
14
|
+
# Replace variables (defined in sprintf syntax) in given <i>string</i> with values from <i>variables</i> hash.
|
15
|
+
#
|
16
|
+
# If variable value is not found there are 3 possible strategies (configurable via <i>:value_not_found</i> in third <i>options</i> argument):
|
17
|
+
# * :raise - raise argument error
|
18
|
+
# * :ignore - ignore the variable in string (leave as is, do not replace) (DEFAULT)
|
19
|
+
# * :hide - replace the variable in string with empty string
|
20
|
+
def interpolate(string, values, options = {})
|
21
|
+
options[:not_found_strategy] ||= :ignore
|
22
|
+
raise ArgumentError.new('Interpolation values must be a Hash.') unless values.kind_of?(Hash)
|
23
|
+
interpolate_hash(string, values, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def interpolate_hash(string, values, options)
|
27
|
+
string.gsub(INTERPOLATION_PATTERN) do |match|
|
28
|
+
if match == '%%'
|
29
|
+
'%'
|
30
|
+
else
|
31
|
+
key = ($1 || $2).to_sym
|
32
|
+
if values.key?(key)
|
33
|
+
value = values[key]
|
34
|
+
value = value.call(values) if value.respond_to?(:call)
|
35
|
+
$3 ? sprintf("%#{$3}", value) : value
|
36
|
+
else
|
37
|
+
if options[:not_found_strategy] == :raise
|
38
|
+
raise ArgumentError.new("missing interpolation argument #{key} in #{string.inspect}. Given values are: (#{values.inspect})")
|
39
|
+
elsif options[:not_found_strategy] == :hide
|
40
|
+
value = ''
|
41
|
+
else
|
42
|
+
value = $&
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/string.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
# returns a hash like params containing all the "get" params from a given url
|
4
|
+
# Ex:
|
5
|
+
# 'http://wiki.rego.co.il/doku.php?id=development:horizon3:plugins:core_extensions:start&do=edit&rev='.to_params
|
6
|
+
# => {:id=>'development:horizon3:plugins:core_extensions:start', :do=>'edit', :rev=>nil}
|
7
|
+
def to_params
|
8
|
+
hash = {}
|
9
|
+
params=self.split("?")
|
10
|
+
if params.size > 1
|
11
|
+
params=params[1].split("&")
|
12
|
+
params=params.collect{|param| param.split("=")}
|
13
|
+
params.each do |param|
|
14
|
+
hash[param[0].to_sym]=param[1]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
hash
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# matches and replaces placeholders in form of %{foo} or %<foo>
|
22
|
+
def interpolate(values_hash = {}, options = {})
|
23
|
+
StringInterpolation.interpolate(self, values_hash, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/symbol.rb
ADDED
data/lib/time.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rego-ruby-ext}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Alex Tkachev"]
|
12
|
+
s.date = %q{2011-08-21}
|
13
|
+
s.description = %q{Ruby core extensions that are common for all ReGO projects}
|
14
|
+
s.email = %q{tkachev.alex@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"init.rb",
|
28
|
+
"lib/date.rb",
|
29
|
+
"lib/enumerable.rb",
|
30
|
+
"lib/nil.rb",
|
31
|
+
"lib/numeric.rb",
|
32
|
+
"lib/rego-ruby-ext.rb",
|
33
|
+
"lib/string-interpolation.rb",
|
34
|
+
"lib/string.rb",
|
35
|
+
"lib/symbol.rb",
|
36
|
+
"lib/time.rb",
|
37
|
+
"rego-ruby-ext.gemspec",
|
38
|
+
"spec/date_spec.rb",
|
39
|
+
"spec/enumerable_spec.rb",
|
40
|
+
"spec/nil_spec.rb",
|
41
|
+
"spec/numeric_spec.rb",
|
42
|
+
"spec/rego-ruby-ext_spec.rb",
|
43
|
+
"spec/spec_helper.rb",
|
44
|
+
"spec/string_interpolation_spec.rb",
|
45
|
+
"spec/string_spec.rb",
|
46
|
+
"spec/symbol_spec.rb",
|
47
|
+
"spec/time_spec.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/alextk/rego-ruby-ext}
|
50
|
+
s.licenses = ["MIT"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.4.2}
|
53
|
+
s.summary = %q{Some basic ruby core classes extensions with tests}
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
60
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
61
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
62
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
63
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
67
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
69
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
70
|
+
end
|
71
|
+
else
|
72
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
74
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
76
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
data/spec/date_spec.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Enumerable do
|
4
|
+
describe "#find_by_" do
|
5
|
+
before :each do
|
6
|
+
@full_names = [
|
7
|
+
{:name=>'Yosi', :last_name=>'Posi'},
|
8
|
+
{:name=>'Guy', :last_name=>'Shmuely'},
|
9
|
+
{:name=>'Jack', :last_name=>'Sparrow'}
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should find one result' do
|
14
|
+
result = @full_names.select_by_name_and_last_name('Guy','Shmuely')
|
15
|
+
|
16
|
+
result.size.should == 1
|
17
|
+
result.first.should == @full_names[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not find any results' do
|
21
|
+
@full_names.select_by_name('asdf').should be_empty
|
22
|
+
[].select_by_name('asdf').should be_empty
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#collect_" do
|
27
|
+
before :each do
|
28
|
+
@full_names = [
|
29
|
+
{:name=>'Yosi', :last_name=>'Posi'},
|
30
|
+
{:name=>'Guy', :last_name=>'Shmuely'},
|
31
|
+
{:name=>'Jack', :last_name=>'Sparrow'}
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should collect names' do
|
36
|
+
first_names = @full_names.collect_name
|
37
|
+
|
38
|
+
first_names.size.should == 3
|
39
|
+
first_names.should include('Yosi', 'Guy', 'Jack')
|
40
|
+
first_names.should_not include('Baruh')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should collect last_names' do
|
44
|
+
last_names = @full_names.collect_last_name
|
45
|
+
|
46
|
+
last_names.size.should == 3
|
47
|
+
last_names.should include('Posi', 'Sparrow', 'Shmuely')
|
48
|
+
last_names.should_not include('Guy')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/nil_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe NilClass do
|
4
|
+
it "should be empty or blank" do
|
5
|
+
nil.should be_empty
|
6
|
+
nil.should be_blank
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should not include or any' do
|
10
|
+
nil.should_not include(23)
|
11
|
+
nil.should_not be_any
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should raise error on to_sym method' do
|
15
|
+
lambda{ nil.to_sym }.should raise_error
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), "../lib", "rego-ruby-ext")
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe StringInterpolation do
|
4
|
+
describe "#interpolate" do
|
5
|
+
it 'should replace %{} variables' do
|
6
|
+
str = 'my var1=%{var1} and var2 is %{var2}.'
|
7
|
+
StringInterpolation.interpolate(str, :var1 => 'one', :var2 => 'foo').should == 'my var1=one and var2 is foo.'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should replace %<> variables' do
|
11
|
+
str = 'my var1=%<var1>d and var2 is %<var2>s.'
|
12
|
+
StringInterpolation.interpolate(str, :var1 => 5.2, :var2 => 'foo').should == 'my var1=5 and var2 is foo.'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should raise error if variable value not found and strategy is :raise' do
|
16
|
+
str = 'my var1=%<var1>d and var2 is %<var2>s'
|
17
|
+
lambda{ StringInterpolation.interpolate(str, {:var1 => 5.2}, {:not_found_strategy => :raise}) }.should raise_error(ArgumentError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should leave variable intact if value not found (default behaivour)' do
|
21
|
+
str = 'my var1=%{var1} and var2 is %<var2>d'
|
22
|
+
StringInterpolation.interpolate(str, {}).should == 'my var1=%{var1} and var2 is %<var2>d'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should hide variable if variable value not found and strategy is :hide' do
|
26
|
+
str = 'my var1=%{var1} and var2 is %<var2>d.'
|
27
|
+
StringInterpolation.interpolate(str, {}, {:not_found_strategy => :hide}).should == 'my var1= and var2 is .'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/spec/string_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
describe "#to_params" do
|
5
|
+
it 'should return empty params hash for non url or url with no params' do
|
6
|
+
''.to_params.should == {}
|
7
|
+
'http://wiki.rego.co.il/doku.php'.to_params.should == {}
|
8
|
+
'http://wiki.rego.co.il/doku.php?'.to_params.should == {}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse url return params hash" do
|
12
|
+
url = 'http://wiki.rego.co.il/doku.php?id=development:horizon3:plugins:core_extensions:start&do=edit&rev='
|
13
|
+
url.to_params.should == {:do=>"edit", :rev=>nil, :id=>"development:horizon3:plugins:core_extensions:start"}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#interpolate' do
|
18
|
+
"var is %{var1}!".interpolate(:var1 => 10).should == "var is 10!"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/spec/symbol_spec.rb
ADDED
data/spec/time_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rego-ruby-ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alex Tkachev
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-08-21 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
name: rdoc
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 3
|
46
|
+
- 0
|
47
|
+
version: 2.3.0
|
48
|
+
type: :development
|
49
|
+
name: rspec
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 23
|
59
|
+
segments:
|
60
|
+
- 1
|
61
|
+
- 0
|
62
|
+
- 0
|
63
|
+
version: 1.0.0
|
64
|
+
type: :development
|
65
|
+
name: bundler
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 7
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 6
|
78
|
+
- 4
|
79
|
+
version: 1.6.4
|
80
|
+
type: :development
|
81
|
+
name: jeweler
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 3
|
91
|
+
segments:
|
92
|
+
- 0
|
93
|
+
version: "0"
|
94
|
+
type: :development
|
95
|
+
name: rcov
|
96
|
+
version_requirements: *id005
|
97
|
+
description: Ruby core extensions that are common for all ReGO projects
|
98
|
+
email: tkachev.alex@gmail.com
|
99
|
+
executables: []
|
100
|
+
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files:
|
104
|
+
- LICENSE.txt
|
105
|
+
- README.md
|
106
|
+
files:
|
107
|
+
- .document
|
108
|
+
- .rspec
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- init.rb
|
115
|
+
- lib/date.rb
|
116
|
+
- lib/enumerable.rb
|
117
|
+
- lib/nil.rb
|
118
|
+
- lib/numeric.rb
|
119
|
+
- lib/rego-ruby-ext.rb
|
120
|
+
- lib/string-interpolation.rb
|
121
|
+
- lib/string.rb
|
122
|
+
- lib/symbol.rb
|
123
|
+
- lib/time.rb
|
124
|
+
- rego-ruby-ext.gemspec
|
125
|
+
- spec/date_spec.rb
|
126
|
+
- spec/enumerable_spec.rb
|
127
|
+
- spec/nil_spec.rb
|
128
|
+
- spec/numeric_spec.rb
|
129
|
+
- spec/rego-ruby-ext_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
- spec/string_interpolation_spec.rb
|
132
|
+
- spec/string_spec.rb
|
133
|
+
- spec/symbol_spec.rb
|
134
|
+
- spec/time_spec.rb
|
135
|
+
has_rdoc: true
|
136
|
+
homepage: http://github.com/alextk/rego-ruby-ext
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
requirements: []
|
163
|
+
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 1.4.2
|
166
|
+
signing_key:
|
167
|
+
specification_version: 3
|
168
|
+
summary: Some basic ruby core classes extensions with tests
|
169
|
+
test_files: []
|
170
|
+
|