padrino-core 0.7.9 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +8 -6
- data/VERSION +1 -1
- data/lib/padrino-core.rb +2 -0
- data/lib/padrino-core/cli/console.rb +1 -1
- data/lib/padrino-core/logger.rb +1 -1
- data/lib/padrino-core/support_lite.rb +38 -20
- data/padrino-core.gemspec +8 -7
- data/test/test_core.rb +3 -0
- metadata +13 -5
- data/lib/padrino-core/support_lite/as_support.rb +0 -38
- data/lib/padrino-core/support_lite/extlib_support.rb +0 -207
data/Rakefile
CHANGED
@@ -18,7 +18,8 @@ begin
|
|
18
18
|
gem.add_runtime_dependency "usher", ">= 0.6.2"
|
19
19
|
gem.add_runtime_dependency "thor", ">= 0.13.0"
|
20
20
|
gem.add_runtime_dependency "bundler", ">= 0.9.3"
|
21
|
-
gem.
|
21
|
+
gem.add_runtime_dependency "activesupport", ">= 2.3.5"
|
22
|
+
gem.add_development_dependency "shoulda", ">= 2.10.3"
|
22
23
|
gem.add_development_dependency "mocha", ">= 0.9.7"
|
23
24
|
gem.add_development_dependency "rack-test", ">= 0.5.0"
|
24
25
|
gem.add_development_dependency "webrat", ">= 0.5.1"
|
@@ -39,14 +40,15 @@ end
|
|
39
40
|
|
40
41
|
begin
|
41
42
|
require 'rcov/rcovtask'
|
42
|
-
Rcov::RcovTask.new do |
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
Rcov::RcovTask.new do |rcov|
|
44
|
+
rcov.libs << 'test'
|
45
|
+
rcov.pattern = 'test/**/test_*.rb'
|
46
|
+
rcov.verbose = true
|
47
|
+
rcov.rcov_opts << ['--exclude /Gems/1.8/gems/,padrino-admin,padrino-cache,padrino-gen,padrino-helpers,padrino-mailer']
|
46
48
|
end
|
47
49
|
rescue LoadError
|
48
50
|
task :rcov do
|
49
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install
|
51
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install relevance-rcov"
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/lib/padrino-core.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'usher'
|
2
2
|
require 'sinatra/base'
|
3
|
+
|
3
4
|
Dir[File.dirname(__FILE__) + '/padrino-core/*.rb'].each {|file| require file }
|
4
5
|
|
5
6
|
# Defines our PADRINO_ENV
|
@@ -14,6 +15,7 @@ module Padrino
|
|
14
15
|
# Helper method for file references.
|
15
16
|
#
|
16
17
|
# ==== Examples
|
18
|
+
#
|
17
19
|
# # Referencing a file in config called settings.yml
|
18
20
|
# Padrino.root("config", "settings.yml")
|
19
21
|
# # returns PADRINO_ROOT + "/config/setting.yml"
|
data/lib/padrino-core/logger.rb
CHANGED
@@ -249,7 +249,7 @@ module Padrino
|
|
249
249
|
env["REMOTE_USER"] || "-",
|
250
250
|
env["REQUEST_METHOD"],
|
251
251
|
env["PATH_INFO"],
|
252
|
-
env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
|
252
|
+
env["QUERY_STRING"].empty? ? "" : "?" + env["QUERY_STRING"],
|
253
253
|
env["HTTP_VERSION"],
|
254
254
|
status.to_s[0..3],
|
255
255
|
length,
|
@@ -1,6 +1,13 @@
|
|
1
1
|
##
|
2
|
-
# This file
|
3
|
-
#
|
2
|
+
# This file load some usefull extensions from Active Support.
|
3
|
+
#
|
4
|
+
# Why ActiveSupport and not ours or extlib?
|
5
|
+
#
|
6
|
+
# We don't love so much rewite code and we don't use extlib because:
|
7
|
+
#
|
8
|
+
# 1) ActiveRecord need ActiveSupport
|
9
|
+
# 2) MongoMapper need ActiveSuport
|
10
|
+
# 3) DataMapper it's planning to migrate to ActiveSupport (see: http://wiki.github.com/datamapper/dm-core/roadmap)
|
4
11
|
#
|
5
12
|
# Required for Padrino to run:
|
6
13
|
#
|
@@ -16,28 +23,39 @@
|
|
16
23
|
# * Hash#reverse_merge, Hash#reverse_merge!
|
17
24
|
# * SupportLite::OrderedHash
|
18
25
|
#
|
26
|
+
|
19
27
|
require 'i18n'
|
28
|
+
require 'active_support/core_ext/kernel'
|
29
|
+
require 'active_support/core_ext/module'
|
30
|
+
require 'active_support/deprecation'
|
31
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
32
|
+
require 'active_support/core_ext/hash'
|
33
|
+
require 'active_support/inflector'
|
34
|
+
require 'active_support/core_ext/object'
|
35
|
+
require 'active_support/core_ext/object/blank'
|
36
|
+
require 'active_support/core_ext/array'
|
37
|
+
require 'active_support/core_ext/module'
|
38
|
+
require 'active_support/ordered_hash'
|
20
39
|
|
21
40
|
##
|
22
|
-
#
|
41
|
+
# Define our Ordered Hash
|
23
42
|
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
##
|
28
|
-
# Return the current support used.
|
29
|
-
# Can be one of: :extlib, :active_support
|
30
|
-
#
|
31
|
-
def self.support
|
32
|
-
@_padrino_support
|
43
|
+
unless defined?(SupportLite::OrderedHash)
|
44
|
+
module SupportLite
|
45
|
+
OrderedHash = ::ActiveSupport::OrderedHash
|
33
46
|
end
|
47
|
+
end
|
34
48
|
|
35
|
-
|
49
|
+
##
|
50
|
+
# We new alwasy :to_params in a Hash
|
51
|
+
#
|
52
|
+
unless Hash.method_defined?(:to_params)
|
53
|
+
class Hash
|
54
|
+
alias :to_params :to_query
|
55
|
+
end
|
56
|
+
end
|
36
57
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
Padrino.instance_variable_set(:@_padrino_support, :active_support)
|
42
|
-
require File.dirname(__FILE__) + '/support_lite/as_support'
|
43
|
-
end
|
58
|
+
##
|
59
|
+
# Load our locales
|
60
|
+
#
|
61
|
+
I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"]
|
data/padrino-core.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-core}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.8.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{2010-02-
|
12
|
+
s.date = %q{2010-02-14}
|
13
13
|
s.default_executable = %q{padrino}
|
14
14
|
s.description = %q{The Padrino core gem required for use of this framework}
|
15
15
|
s.email = %q{padrinorb@gmail.com}
|
@@ -44,8 +44,6 @@ Gem::Specification.new do |s|
|
|
44
44
|
"lib/padrino-core/reloader.rb",
|
45
45
|
"lib/padrino-core/server.rb",
|
46
46
|
"lib/padrino-core/support_lite.rb",
|
47
|
-
"lib/padrino-core/support_lite/as_support.rb",
|
48
|
-
"lib/padrino-core/support_lite/extlib_support.rb",
|
49
47
|
"lib/padrino-core/tasks.rb",
|
50
48
|
"lib/padrino-core/version.rb",
|
51
49
|
"padrino-core.gemspec",
|
@@ -84,7 +82,8 @@ Gem::Specification.new do |s|
|
|
84
82
|
s.add_runtime_dependency(%q<usher>, [">= 0.6.2"])
|
85
83
|
s.add_runtime_dependency(%q<thor>, [">= 0.13.0"])
|
86
84
|
s.add_runtime_dependency(%q<bundler>, [">= 0.9.3"])
|
87
|
-
s.
|
85
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
|
86
|
+
s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
|
88
87
|
s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
|
89
88
|
s.add_development_dependency(%q<rack-test>, [">= 0.5.0"])
|
90
89
|
s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
|
@@ -94,7 +93,8 @@ Gem::Specification.new do |s|
|
|
94
93
|
s.add_dependency(%q<usher>, [">= 0.6.2"])
|
95
94
|
s.add_dependency(%q<thor>, [">= 0.13.0"])
|
96
95
|
s.add_dependency(%q<bundler>, [">= 0.9.3"])
|
97
|
-
s.add_dependency(%q<
|
96
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
97
|
+
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
98
98
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
99
99
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
100
100
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
@@ -105,7 +105,8 @@ Gem::Specification.new do |s|
|
|
105
105
|
s.add_dependency(%q<usher>, [">= 0.6.2"])
|
106
106
|
s.add_dependency(%q<thor>, [">= 0.13.0"])
|
107
107
|
s.add_dependency(%q<bundler>, [">= 0.9.3"])
|
108
|
-
s.add_dependency(%q<
|
108
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.5"])
|
109
|
+
s.add_dependency(%q<shoulda>, [">= 2.10.3"])
|
109
110
|
s.add_dependency(%q<mocha>, [">= 0.9.7"])
|
110
111
|
s.add_dependency(%q<rack-test>, [">= 0.5.0"])
|
111
112
|
s.add_dependency(%q<webrat>, [">= 0.5.1"])
|
data/test/test_core.rb
CHANGED
@@ -12,11 +12,14 @@ class TestCore < Test::Unit::TestCase
|
|
12
12
|
assert_respond_to Padrino, :load!
|
13
13
|
assert_respond_to Padrino, :reload!
|
14
14
|
assert_respond_to Padrino, :version
|
15
|
+
assert_respond_to Padrino, :bundle
|
15
16
|
end
|
16
17
|
|
17
18
|
should 'validate global helpers' do
|
18
19
|
assert_equal :test, Padrino.env
|
19
20
|
assert_match /\/test/, Padrino.root
|
21
|
+
assert_equal nil, Padrino.bundle
|
22
|
+
assert_not_nil Padrino.version
|
20
23
|
end
|
21
24
|
|
22
25
|
should 'set correct utf-8 encoding' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2010-02-
|
15
|
+
date: 2010-02-14 00:00:00 +01:00
|
16
16
|
default_executable: padrino
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -65,6 +65,16 @@ dependencies:
|
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: 0.9.3
|
67
67
|
version:
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: activesupport
|
70
|
+
type: :runtime
|
71
|
+
version_requirement:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.3.5
|
77
|
+
version:
|
68
78
|
- !ruby/object:Gem::Dependency
|
69
79
|
name: shoulda
|
70
80
|
type: :development
|
@@ -73,7 +83,7 @@ dependencies:
|
|
73
83
|
requirements:
|
74
84
|
- - ">="
|
75
85
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
86
|
+
version: 2.10.3
|
77
87
|
version:
|
78
88
|
- !ruby/object:Gem::Dependency
|
79
89
|
name: mocha
|
@@ -140,8 +150,6 @@ files:
|
|
140
150
|
- lib/padrino-core/reloader.rb
|
141
151
|
- lib/padrino-core/server.rb
|
142
152
|
- lib/padrino-core/support_lite.rb
|
143
|
-
- lib/padrino-core/support_lite/as_support.rb
|
144
|
-
- lib/padrino-core/support_lite/extlib_support.rb
|
145
153
|
- lib/padrino-core/tasks.rb
|
146
154
|
- lib/padrino-core/version.rb
|
147
155
|
- padrino-core.gemspec
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# This requires necessary pieces of ActiveSupport for the dependencies required by Padrino
|
2
|
-
|
3
|
-
## ActiveSupport#Version
|
4
|
-
require 'active_support/version'
|
5
|
-
## ActiveSupport#Deprecation
|
6
|
-
unless defined?(ActiveSupport::Deprecation)
|
7
|
-
require 'active_support/core_ext/kernel' unless Kernel.method_defined?(:silence_warnings)
|
8
|
-
require 'active_support/core_ext/module' unless Module.method_defined?(:mattr_accessor)
|
9
|
-
require 'active_support/deprecation'
|
10
|
-
end
|
11
|
-
## Class#cattr_accessor
|
12
|
-
require 'active_support/core_ext/class/attribute_accessors' unless Class.method_defined?(:cattr_accessor)
|
13
|
-
## Hash#symbolize_keys, Hash#reverse_merge, Hash#reverse_merge!, Hash#extract_options!, Hash#slice!
|
14
|
-
require 'active_support/core_ext/hash' unless Hash.method_defined?(:reverse_merge)
|
15
|
-
## Hash#to_params
|
16
|
-
require 'active_support/core_ext/object' unless Object.method_defined?(:to_query)
|
17
|
-
class Hash; alias :to_params :to_query; end unless Hash.method_defined?(:to_params)
|
18
|
-
## Object#with_options
|
19
|
-
require 'active_support/option_merger'
|
20
|
-
## String#inflectors
|
21
|
-
require 'active_support/inflector' unless String.method_defined?(:constantize)
|
22
|
-
## Object#blank?, Object#present?
|
23
|
-
require 'active_support/core_ext/object' unless Object.method_defined?(:blank?)
|
24
|
-
require 'active_support/core_ext/blank' unless Object.method_defined?(:blank?)
|
25
|
-
## Array#extract_options!
|
26
|
-
require 'active_support/core_ext/array' unless Array.method_defined?(:extract_options!)
|
27
|
-
## Module#alias_method_chain
|
28
|
-
require 'active_support/core_ext/module' unless Module.method_defined?(:alias_method_chain)
|
29
|
-
## SupportLite#OrderedHash
|
30
|
-
require 'active_support/ordered_hash' unless defined?(ActiveSupport::OrderedHash)
|
31
|
-
## Float#round
|
32
|
-
require 'active_support/core_ext/float/rounding'
|
33
|
-
|
34
|
-
unless defined?(SupportLite::OrderedHash)
|
35
|
-
module SupportLite
|
36
|
-
OrderedHash = ::ActiveSupport::OrderedHash
|
37
|
-
end
|
38
|
-
end
|
@@ -1,207 +0,0 @@
|
|
1
|
-
# This helps extlib to act like ActiveSupport for use with Padrino
|
2
|
-
|
3
|
-
## Class#cattr_accessor
|
4
|
-
unless Class.method_defined?(:cattr_accessor)
|
5
|
-
require 'extlib/class'
|
6
|
-
end
|
7
|
-
|
8
|
-
## SupportLite::OrderedHash
|
9
|
-
unless defined?(SupportLite::OrderedHash)
|
10
|
-
require 'extlib/dictionary'
|
11
|
-
module SupportLite
|
12
|
-
OrderedHash = ::Dictionary
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
## Hash#symbolize_keys
|
17
|
-
unless Hash.method_defined?(:symbolize_keys)
|
18
|
-
require 'extlib/hash'
|
19
|
-
require 'extlib/mash'
|
20
|
-
class Hash
|
21
|
-
def symbolize_keys
|
22
|
-
Mash.new(self).symbolize_keys
|
23
|
-
end
|
24
|
-
|
25
|
-
def symbolize_keys!
|
26
|
-
self.replace(symbolize_keys.to_hash)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
## Hash#slice, Hash#slice!
|
32
|
-
unless Hash.method_defined?(:slice)
|
33
|
-
require 'extlib/hash'
|
34
|
-
class Hash
|
35
|
-
# Slice a hash to include only the given keys. This is useful for
|
36
|
-
# limiting an options hash to valid keys before passing to a method:
|
37
|
-
#
|
38
|
-
# def search(criteria = {})
|
39
|
-
# assert_valid_keys(:mass, :velocity, :time)
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# search(options.slice(:mass, :velocity, :time))
|
43
|
-
#
|
44
|
-
# If you have an array of keys you want to limit to, you should splat them:
|
45
|
-
#
|
46
|
-
# valid_keys = [:mass, :velocity, :time]
|
47
|
-
# search(options.slice(*valid_keys))
|
48
|
-
def slice(*keys)
|
49
|
-
keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
|
50
|
-
hash = self.class.new
|
51
|
-
keys.each { |k| hash[k] = self[k] if has_key?(k) }
|
52
|
-
hash
|
53
|
-
end
|
54
|
-
|
55
|
-
# Replaces the hash with only the given keys.
|
56
|
-
# Returns a hash contained the removed key/value pairs
|
57
|
-
# {:a => 1, :b => 2, :c => 3, :d => 4}.slice!(:a, :b) # => {:c => 3, :d =>4}
|
58
|
-
def slice!(*keys)
|
59
|
-
keys = keys.map! { |key| convert_key(key) } if respond_to?(:convert_key)
|
60
|
-
omit = slice(*self.keys - keys)
|
61
|
-
hash = slice(*keys)
|
62
|
-
replace(hash)
|
63
|
-
omit
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
## Hash#to_params
|
69
|
-
unless Hash.method_defined?(:to_params)
|
70
|
-
require 'extlib/hash'
|
71
|
-
end
|
72
|
-
|
73
|
-
## Hash#reverse_merge, Hash#reverse_merge!
|
74
|
-
unless Hash.method_defined?(:reverse_merge)
|
75
|
-
class Hash
|
76
|
-
def reverse_merge(other_hash)
|
77
|
-
other_hash.merge(self)
|
78
|
-
end
|
79
|
-
|
80
|
-
def reverse_merge!(other_hash)
|
81
|
-
replace(reverse_merge(other_hash))
|
82
|
-
end
|
83
|
-
|
84
|
-
def deep_merge(other_hash)
|
85
|
-
target = dup
|
86
|
-
other_hash.each_pair do |k,v|
|
87
|
-
tv = target[k]
|
88
|
-
target[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
|
89
|
-
end
|
90
|
-
target
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
## Array#extract_options!
|
96
|
-
unless Array.method_defined?(:extract_options!)
|
97
|
-
class Array
|
98
|
-
def extract_options!
|
99
|
-
last.is_a?(::Hash) ? pop : {}
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
## String#inflectors
|
105
|
-
unless String.method_defined?(:constantize)
|
106
|
-
require 'extlib/inflection'
|
107
|
-
class String
|
108
|
-
def classify; Extlib::Inflection.classify(self); end
|
109
|
-
def underscore; Extlib::Inflection.underscore(self); end
|
110
|
-
def constantize; Extlib::Inflection.constantize(self); end
|
111
|
-
def camelize; Extlib::Inflection.camelize(self); end
|
112
|
-
def humanize; Extlib::Inflection.humanize(self); end
|
113
|
-
alias :titleize :humanize
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
## Object#blank?
|
118
|
-
unless Object.method_defined?(:blank?)
|
119
|
-
require 'extlib/blank'
|
120
|
-
end
|
121
|
-
|
122
|
-
## Object#present?
|
123
|
-
unless Object.method_defined?(:present?)
|
124
|
-
class Object
|
125
|
-
def present?
|
126
|
-
!blank?
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
## Object#with_options
|
132
|
-
unless Object.method_defined?(:with_options)
|
133
|
-
class SupportLite::OptionMerger #:nodoc:
|
134
|
-
instance_methods.each do |method|
|
135
|
-
undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
|
136
|
-
end
|
137
|
-
|
138
|
-
def initialize(context, options)
|
139
|
-
@context, @options = context, options
|
140
|
-
end
|
141
|
-
|
142
|
-
private
|
143
|
-
def method_missing(method, *arguments, &block)
|
144
|
-
if arguments.last.is_a?(Proc)
|
145
|
-
proc = arguments.pop
|
146
|
-
arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
|
147
|
-
else
|
148
|
-
arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
|
149
|
-
end
|
150
|
-
|
151
|
-
@context.__send__(method, *arguments, &block)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
class Object
|
156
|
-
def with_options(options)
|
157
|
-
yield SupportLite::OptionMerger.new(self, options)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
## Module#alias_method_chain
|
163
|
-
unless Module.method_defined?(:alias_method_chain)
|
164
|
-
def alias_method_chain(target, feature)
|
165
|
-
# Strip out punctuation on predicates or bang methods since
|
166
|
-
# e.g. target?_without_feature is not a valid method name.
|
167
|
-
aliased_target, punctuation = target.to_s.sub(/([?!=])$/, ''), $1
|
168
|
-
yield(aliased_target, punctuation) if block_given?
|
169
|
-
|
170
|
-
with_method, without_method = "#{aliased_target}_with_#{feature}#{punctuation}", "#{aliased_target}_without_#{feature}#{punctuation}"
|
171
|
-
|
172
|
-
alias_method without_method, target
|
173
|
-
alias_method target, with_method
|
174
|
-
|
175
|
-
case
|
176
|
-
when public_method_defined?(without_method)
|
177
|
-
public target
|
178
|
-
when protected_method_defined?(without_method)
|
179
|
-
protected target
|
180
|
-
when private_method_defined?(without_method)
|
181
|
-
private target
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
## Float#round
|
187
|
-
unless Float.method_defined?(:round)
|
188
|
-
class Float
|
189
|
-
alias precisionless_round round
|
190
|
-
private :precisionless_round
|
191
|
-
|
192
|
-
# Rounds the float with the specified precision.
|
193
|
-
#
|
194
|
-
# x = 1.337
|
195
|
-
# x.round # => 1
|
196
|
-
# x.round(1) # => 1.3
|
197
|
-
# x.round(2) # => 1.34
|
198
|
-
def round(precision = nil)
|
199
|
-
if precision
|
200
|
-
magnitude = 10.0 ** precision
|
201
|
-
(self * magnitude).round / magnitude
|
202
|
-
else
|
203
|
-
precisionless_round
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|