santas_little_helper 0.0.10 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/santas_little_helper.rb +156 -71
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5e3c2d83766c76407d80f95c14a3b7c216ce412
|
4
|
+
data.tar.gz: fff37c2f2aa5859d5a605788fa27762665969215
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 456c5508c334efddce6e879c4ba5bd7315192b6850ec54c1746af24b2e315475068049b54c8e717a2b7371485ae765910cb2e35d872cb6b8648609560baf42cc
|
7
|
+
data.tar.gz: 0e18b2d96daefac5a37bf9306183dc00d5b360724317eeece16df2e9429339d01959e2f4a6c66e1189353326ab7c37cd2d75f08c31b0ed0b2d6a00b6d1afdef2
|
data/lib/santas_little_helper.rb
CHANGED
@@ -9,20 +9,43 @@
|
|
9
9
|
# Not really worried about maglev & rubinius & ironruby right now - as they are not really mutiplatform, not as widespread and I can't test for
|
10
10
|
# them right now.
|
11
11
|
|
12
|
-
|
13
|
-
def
|
14
|
-
|
15
|
-
|
12
|
+
|
13
|
+
def ruby_platform
|
14
|
+
case RUBY_PLATFORM
|
15
|
+
when /win32|mswin|mingw/
|
16
|
+
# Works on Windows XP, 2003, 7, 8 running Ruby 1.8.6 & 1.8.7, 1.9.2, 1.9.3 & 2.0.0 installed from RubyInstaller
|
17
|
+
# Can't match for just 'win' cause it will match darwin as well.
|
18
|
+
'windows'
|
19
|
+
when /linux/
|
20
|
+
# Works on Debian Sarge, Lenny & Wheezy and Ubuntu 9.10 running REE 1.8.7 & MRI 2.0.0 32-bit & 64-bit, don't have anything else to test on.
|
21
|
+
'linux'
|
22
|
+
when /darwin/
|
23
|
+
# Works on my MacBook Pro OS 10.6 running Ruby 1.8.7 and .rbenv version of 1.9.3 & 2.0.0 , don't have anything else to test on,
|
24
|
+
'mac'
|
25
|
+
when /java/
|
26
|
+
'jruby'
|
27
|
+
when /i386|x86_64|x86/
|
28
|
+
# I'm actually not sure what rubinius or maglev or other implementions would return. I don't rubies, other than mri or jruby.
|
29
|
+
'mri'
|
30
|
+
else
|
31
|
+
nil
|
32
|
+
end
|
16
33
|
end
|
17
34
|
|
18
|
-
|
19
|
-
|
20
|
-
|
35
|
+
def ruby_platform?(os='')
|
36
|
+
# Takes a string or a method like so platform?(:windows)
|
37
|
+
os.to_s.match(ruby_platform) ? true : false
|
21
38
|
end
|
22
39
|
|
23
|
-
#
|
40
|
+
# These are just aliases for convinience, I really doubt somebody would use them System Wide on an object for any other purpose.
|
41
|
+
def windows?
|
42
|
+
ruby_platform?(:windows)
|
43
|
+
end
|
44
|
+
def linux?
|
45
|
+
ruby_platform?(:linux)
|
46
|
+
end
|
24
47
|
def mac?
|
25
|
-
(
|
48
|
+
ruby_platform?(:mac)
|
26
49
|
end
|
27
50
|
|
28
51
|
|
@@ -30,78 +53,140 @@ end
|
|
30
53
|
# I test and deploy some of the project on jruby - this makes it easier to customize my gemfiles.
|
31
54
|
# Works for ruby 1.8.7 & 1.9.3 & 1.9.2 on windows( 7 & xp) & linux ( debian Lenny) using rubyinstaller for windows and using mri ruby buillt from source for linux
|
32
55
|
# Works for jruby 1.7.0.rc1 and jruby 1.6.3 on windows (7 & xp)
|
56
|
+
# At this point it's essentially just an alias fro platform & platform?, since it queries RUBY_PLATFORM, but this may change in the future
|
57
|
+
# In the future I may start using RUBY_ENGINE
|
58
|
+
def ruby_implementation
|
59
|
+
ruby_platform
|
60
|
+
end
|
61
|
+
def ruby_implementation?(written_in='')
|
62
|
+
ruby_platform?(written_in)
|
63
|
+
end
|
33
64
|
def jruby?
|
34
|
-
(
|
65
|
+
ruby_implementation?(:jruby)
|
35
66
|
end
|
36
|
-
|
37
67
|
def mri?
|
38
|
-
(
|
68
|
+
ruby_implementation?(:mri)
|
39
69
|
end
|
40
70
|
|
41
71
|
|
42
72
|
# In case ruby ever reaches version 19 :-) or some 2.19 :-) only matching 1.9 at the begining of the line
|
43
|
-
|
44
|
-
|
73
|
+
# Returns an integer for easy version comparison 200 > 187 ( Version two is newer :-) )
|
74
|
+
# if ruby_version > 187 , install new version of the gem.
|
75
|
+
def ruby_version
|
76
|
+
RUBY_VERSION.gsub(/[^0-9]/,'').to_i
|
45
77
|
end
|
46
|
-
|
47
|
-
|
48
|
-
(
|
78
|
+
def ruby_version?(version_to_check)
|
79
|
+
# Be careful - this will only match up to minor release. It will not match patch versions.
|
80
|
+
# You can ask it things in the following formats ruby_version?(1), ruby_version?(1.8), ruby_version?('200')
|
81
|
+
version_to_check = version_to_check.to_s.gsub(/[^0-9]/,'')
|
82
|
+
RUBY_VERSION.gsub(/[^0-9]/,'')[0..(version_to_check.size-1)] == version_to_check[0..(version_to_check.size-1)]
|
49
83
|
end
|
50
84
|
|
51
85
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
86
|
+
if ruby_version >= 200
|
87
|
+
module SantasLittleHelper
|
88
|
+
|
89
|
+
# When something is True / False and I can to_s it, why can't I to_i it?
|
90
|
+
# There is actually a good theoretical reason, but in real world it really helps if you can output true or false
|
91
|
+
# as an int when you are sending soap request to a client, whose api requires it as 1 or 0, or humanize to "yes" & "no" form
|
92
|
+
# since users apperently are not good at understaning what true or false means in some context.
|
93
|
+
# Also why this can be done at a presentation level, when you are trying to create a meta method to handle complex objects
|
94
|
+
# this is much more convinient and readable.
|
95
|
+
# For an alternative solution check out http://www.ruby-forum.com/topic/206789#new
|
96
|
+
|
97
|
+
|
98
|
+
refine TrueClass do
|
99
|
+
# Rails conventions for boolean / tinyint
|
100
|
+
def to_i
|
101
|
+
1
|
102
|
+
end
|
103
|
+
|
104
|
+
# Humanize. to_s returns "true"
|
105
|
+
def to_human
|
106
|
+
"yes"
|
107
|
+
end
|
108
|
+
|
109
|
+
# Really?! Do I need to spell it out to you?
|
110
|
+
def to_teenager
|
111
|
+
"Yeah, yeah. Here you go. Did you get what you came for? Now disappear."
|
112
|
+
end
|
113
|
+
end
|
114
|
+
refine FalseClass do
|
115
|
+
# Rails conventions for boolean / tinyint
|
116
|
+
def to_i
|
117
|
+
0
|
118
|
+
end
|
119
|
+
|
120
|
+
# Humanize. to_s returns "false".
|
121
|
+
def to_human
|
122
|
+
"no"
|
123
|
+
end
|
124
|
+
|
125
|
+
# Little obnoxious teenager.
|
126
|
+
def to_teenager
|
127
|
+
"No means no!!! Can't you leave me alone?"
|
128
|
+
end
|
129
|
+
end
|
130
|
+
refine NilClass do
|
131
|
+
# Since in if/else nil is interpreted as false, return same as false.
|
132
|
+
def to_i
|
133
|
+
0
|
134
|
+
end
|
135
|
+
|
136
|
+
# Humanize. to_s returns "" as well, this is really to be consistent with other classes.
|
137
|
+
def to_human
|
138
|
+
""
|
139
|
+
end
|
140
|
+
|
141
|
+
# A very rude teenager nihilist.
|
142
|
+
def to_teenager
|
143
|
+
"Zip! Nada! Babkis! Nothing to see here! Get out of my room!"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
refine String do
|
147
|
+
# See http://stackoverflow.com/questions/8119970/string-true-and-false-to-boolean
|
148
|
+
# In this context empty string is nil which is the same as false
|
149
|
+
def to_boolean
|
150
|
+
!!(self =~ /^(true|t|yes|y|1)$/i)
|
151
|
+
end
|
152
|
+
def to_human
|
153
|
+
self.to_s
|
154
|
+
end
|
155
|
+
def to_teenager
|
156
|
+
"What did you say to me? What? #{self.to_human}"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
refine Integer do
|
160
|
+
# Same idea as string: 1 or any number (positive) is true, 0 or negative number is false
|
161
|
+
def to_boolean
|
162
|
+
if self <= 0
|
163
|
+
false
|
164
|
+
else
|
165
|
+
true
|
166
|
+
end
|
167
|
+
end
|
168
|
+
def to_human
|
169
|
+
self.to_s
|
170
|
+
end
|
171
|
+
def to_teenager
|
172
|
+
"I'm not good with whole numbers! I don't like math! Take your #{self.to_human} and go bother someone else!"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
refine Numeric do
|
176
|
+
# Same idea as string: 1 or any number (positive) is true, 0 or negative number is false
|
177
|
+
def to_boolean
|
178
|
+
if self <= 0
|
179
|
+
false
|
180
|
+
else
|
181
|
+
true
|
182
|
+
end
|
183
|
+
end
|
184
|
+
def to_human
|
185
|
+
self.to_s
|
186
|
+
end
|
187
|
+
def to_teenager
|
188
|
+
"I told you I'm not good with whole numbers, what makes you think, I'm good with with fractions like this? #{self.to_human}"
|
189
|
+
end
|
190
|
+
end
|
106
191
|
end
|
107
192
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: santas_little_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Gorbikoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
This is a collection of useful little snippets that I used through out various projects. If there is something you would like to add either check it out and modify it the way you want or let me know and I might add it here.
|
@@ -21,7 +21,8 @@ files:
|
|
21
21
|
homepage: https://github.com/konung/santas_little_helper
|
22
22
|
licenses: []
|
23
23
|
metadata: {}
|
24
|
-
post_install_message:
|
24
|
+
post_install_message: "\n\n\n\n !!!!!!!\n\n This version of Santas Little Helper
|
25
|
+
introduces some major changes. Read source, method_names changed! \n\n\n"
|
25
26
|
rdoc_options: []
|
26
27
|
require_paths:
|
27
28
|
- lib
|
@@ -43,4 +44,4 @@ specification_version: 4
|
|
43
44
|
summary: It's dumb just like the famous dog, but it may surprise you. It modifies
|
44
45
|
core classes, use at your own risk!
|
45
46
|
test_files: []
|
46
|
-
has_rdoc:
|
47
|
+
has_rdoc: false
|