lazier 3.3.7 → 3.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/Lazier.html +169 -34
- data/doc/Lazier/Boolean.html +1 -1
- data/doc/Lazier/Configuration.html +1 -1
- data/doc/Lazier/DateTime.html +1 -1
- data/doc/Lazier/DateTime/ClassMethods.html +1 -1
- data/doc/Lazier/Exceptions.html +1 -1
- data/doc/Lazier/Exceptions/Debug.html +1 -1
- data/doc/Lazier/Exceptions/MissingTranslation.html +1 -1
- data/doc/Lazier/Hash.html +1 -1
- data/doc/Lazier/I18n.html +1 -1
- data/doc/Lazier/Localizer.html +1 -1
- data/doc/Lazier/Math.html +1 -1
- data/doc/Lazier/Math/ClassMethods.html +1 -1
- data/doc/Lazier/Object.html +62 -61
- data/doc/Lazier/Pathname.html +1 -1
- data/doc/Lazier/Settings.html +1 -1
- data/doc/Lazier/String.html +1 -1
- data/doc/Lazier/TimeZone.html +1 -1
- data/doc/Lazier/TimeZone/ClassMethods.html +1 -1
- data/doc/Lazier/Version.html +2 -2
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/method_list.html +109 -103
- data/doc/top-level-namespace.html +1 -1
- data/lazier.gemspec +1 -1
- data/lib/lazier.rb +14 -4
- data/lib/lazier/object.rb +6 -4
- data/lib/lazier/version.rb +1 -1
- data/spec/lazier/object_spec.rb +8 -4
- data/spec/lazier_spec.rb +21 -0
- metadata +3 -3
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Mon Sep 2 17:35:26 2013 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.7 (ruby-2.0.0).
|
109
109
|
</div>
|
data/lazier.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
|
|
25
25
|
gem.required_ruby_version = ">= 1.9.3"
|
26
26
|
|
27
27
|
gem.add_dependency("json", "~> 1.8.0")
|
28
|
-
gem.add_dependency("
|
28
|
+
gem.add_dependency("activesupport", ">= 3.2.13") # We don't use ~> to enable use with 4.0
|
29
29
|
gem.add_dependency("tzinfo", ">= 0.3.37") # We don't use ~> to enable use with 0.3.37 (required by activesupport 4.0) and 1.x, which is the latest available
|
30
30
|
gem.add_dependency("r18n-desktop", "~> 1.1.5")
|
31
31
|
gem.add_dependency("hashie", "~> 2.0.5")
|
data/lib/lazier.rb
CHANGED
@@ -6,8 +6,7 @@
|
|
6
6
|
|
7
7
|
require "json"
|
8
8
|
require "tzinfo"
|
9
|
-
require "active_support/
|
10
|
-
require "action_view"
|
9
|
+
require "active_support/core_ext"
|
11
10
|
require "r18n-desktop"
|
12
11
|
require "hashie"
|
13
12
|
|
@@ -109,7 +108,7 @@ module Lazier
|
|
109
108
|
# Finds a class to instantiate.
|
110
109
|
#
|
111
110
|
# @param cls [Symbol|String|Object] If a `String` or a `Symbol` or a `Class`, then it will be the class to instantiate. Otherwise the class of the object will returned.
|
112
|
-
# @param scope [String] An additional scope to find the class. `%CLASS
|
111
|
+
# @param scope [String] An additional scope to find the class. `%CLASS%`, `%`, `$`, `?` and `@` will be substituted with the class name.
|
113
112
|
# @param only_in_scope [Boolean] If only try to instantiate the class in the scope.
|
114
113
|
# @return [Class] The found class.
|
115
114
|
def self.find_class(cls, scope = "::%CLASS%", only_in_scope = false)
|
@@ -123,13 +122,24 @@ module Lazier
|
|
123
122
|
rv = search_class(cls) # Search outside scope
|
124
123
|
end
|
125
124
|
|
126
|
-
rv = search_class(scope.to_s.gsub(
|
125
|
+
rv = search_class(scope.to_s.gsub(/%CLASS%|[@%$?]/, cls)) if !rv && cls !~ /^::/ && scope.present? # Search inside scope
|
127
126
|
rv || raise(NameError.new("", cls))
|
128
127
|
else
|
129
128
|
cls.is_a?(::Class) ? cls : cls.class
|
130
129
|
end
|
131
130
|
end
|
132
131
|
|
132
|
+
# Measure the time in milliseconds required to execute the given block.
|
133
|
+
#
|
134
|
+
# @param message [String|NilClass] An optional message (see return value).
|
135
|
+
# @param precision [Fixnum] The precision for the message (see return value)..
|
136
|
+
# @param block [Proc] The block to evaluate.
|
137
|
+
# @return [Float|String] If a `message` is provided, then the message itself plus the duration under parenthesis will be returned, otherwise the duration alone as a number.
|
138
|
+
def self.benchmark(message = nil, precision = 0, &block)
|
139
|
+
rv = Benchmark.ms(&block)
|
140
|
+
message ? ("%s (%0.#{precision}f ms)" % [message, rv]) : rv
|
141
|
+
end
|
142
|
+
|
133
143
|
private
|
134
144
|
# Tries to search a class.
|
135
145
|
#
|
data/lib/lazier/object.rb
CHANGED
@@ -7,7 +7,6 @@
|
|
7
7
|
module Lazier
|
8
8
|
# Extensions for all objects.
|
9
9
|
module Object
|
10
|
-
include ::ActionView::Helpers::NumberHelper
|
11
10
|
extend ::ActiveSupport::Concern
|
12
11
|
|
13
12
|
# Expression to match a boolean value.
|
@@ -141,7 +140,7 @@ module Lazier
|
|
141
140
|
# @param precision [Fixnum] The precision to keep.
|
142
141
|
# @return [Float] The rounded float representaton of the object.
|
143
142
|
def round_to_precision(precision = 2)
|
144
|
-
is_number? ?
|
143
|
+
is_number? ? to_float.round([precision, 0].max) : nil
|
145
144
|
end
|
146
145
|
|
147
146
|
# Formats a number.
|
@@ -156,9 +155,12 @@ module Lazier
|
|
156
155
|
if is_number? then
|
157
156
|
settings = ::Lazier.settings.format_number
|
158
157
|
add_string ||= settings[:add_string]
|
159
|
-
format, unit = (add_string ? ["%n %u", add_string] : ["%n", ""])
|
160
158
|
|
161
|
-
|
159
|
+
rv = ("%0.#{[precision || settings[:precision], 0].max}f" % to_float).split(".")
|
160
|
+
rv[0].gsub!(/(\d)(?=(\d{3})+(?!\d))/, "\\1#{k_separator || settings[:k_separator]}")
|
161
|
+
rv = rv.join(decimal_separator || settings[:decimal_separator])
|
162
|
+
rv += " #{add_string}" if add_string
|
163
|
+
rv
|
162
164
|
else
|
163
165
|
nil
|
164
166
|
end
|
data/lib/lazier/version.rb
CHANGED
data/spec/lazier/object_spec.rb
CHANGED
@@ -251,10 +251,10 @@ describe Lazier::Object do
|
|
251
251
|
|
252
252
|
describe "#round_to_precision" do
|
253
253
|
it "should round number" do
|
254
|
-
expect(123.456789.round_to_precision(2)).to eq(
|
255
|
-
expect(123.456789.round_to_precision(0)).to eq(
|
256
|
-
expect("123.456789".round_to_precision(2)).to eq(
|
257
|
-
expect(123.456789.round_to_precision(-1)).to eq(
|
254
|
+
expect(123.456789.round_to_precision(2)).to eq(123.46)
|
255
|
+
expect(123.456789.round_to_precision(0)).to eq(123)
|
256
|
+
expect("123.456789".round_to_precision(2)).to eq(123.46)
|
257
|
+
expect(123.456789.round_to_precision(-1)).to eq(123)
|
258
258
|
end
|
259
259
|
|
260
260
|
it "should return nil for non numeric values" do
|
@@ -264,7 +264,11 @@ describe Lazier::Object do
|
|
264
264
|
|
265
265
|
describe "#format_number" do
|
266
266
|
it "should format number" do
|
267
|
+
expect(123.format_number(0)).to eq("123")
|
268
|
+
expect(123.456789.format_number).to eq("123.46")
|
269
|
+
expect(12312.456789.format_number).to eq("12,312.46")
|
267
270
|
expect(123123.456789.format_number).to eq("123,123.46")
|
271
|
+
expect(1123123.456789.format_number).to eq("1,123,123.46")
|
268
272
|
expect(123123.456789.format_number(2)).to eq("123,123.46")
|
269
273
|
expect(123123.456789.format_number(3, "@")).to eq("123,123@457")
|
270
274
|
expect(123123.456789.format_number(3, "@", "$")).to eq("123,123@457 $")
|
data/spec/lazier_spec.rb
CHANGED
@@ -52,6 +52,10 @@ describe Lazier do
|
|
52
52
|
it "should return a valid class" do
|
53
53
|
expect(::Lazier.find_class("String")).to eq(String)
|
54
54
|
expect(::Lazier.find_class("TestClass", "::LazierTest::%CLASS%")).to eq(::LazierTest::TestClass)
|
55
|
+
expect(::Lazier.find_class("TestClass", "::LazierTest::@")).to eq(::LazierTest::TestClass)
|
56
|
+
expect(::Lazier.find_class("TestClass", "::LazierTest::$")).to eq(::LazierTest::TestClass)
|
57
|
+
expect(::Lazier.find_class("TestClass", "::LazierTest::?")).to eq(::LazierTest::TestClass)
|
58
|
+
expect(::Lazier.find_class("TestClass", "::LazierTest::%")).to eq(::LazierTest::TestClass)
|
55
59
|
end
|
56
60
|
|
57
61
|
it "should raise an exception if the class is not found" do
|
@@ -74,4 +78,21 @@ describe Lazier do
|
|
74
78
|
expect(::Lazier.find_class(Hash)).to eq(Hash)
|
75
79
|
end
|
76
80
|
end
|
81
|
+
|
82
|
+
describe ".benchmark" do
|
83
|
+
it "should execute the given block" do
|
84
|
+
control = ""
|
85
|
+
Lazier.benchmark { control = "OK" }
|
86
|
+
expect(control).to eq("OK")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "without a message should return the elapsed time" do
|
90
|
+
expect(Lazier.benchmark { control = "OK" }).to be_a(Float)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "with a message should embed the elapsed time into the given message" do
|
94
|
+
expect(Lazier.benchmark("MESSAGE") { control = "OK" }).to match(/^MESSAGE \(\d+ ms\)$/)
|
95
|
+
expect(Lazier.benchmark("MESSAGE", 2) { control = "OK" }).to match(/^MESSAGE \(\d+\.\d+ ms\)$/)
|
96
|
+
end
|
97
|
+
end
|
77
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shogun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - '>='
|