platform_helpers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +23 -0
- data/.gemtest +0 -0
- data/History.txt +6 -0
- data/Manifest.txt +18 -0
- data/README.txt +15 -0
- data/Rakefile +28 -0
- data/lib/platform_helpers/array.rb +31 -0
- data/lib/platform_helpers/bool.rb +37 -0
- data/lib/platform_helpers/browser.rb +218 -0
- data/lib/platform_helpers/date_time.rb +26 -0
- data/lib/platform_helpers/fixnum.rb +15 -0
- data/lib/platform_helpers/float.rb +24 -0
- data/lib/platform_helpers/nil.rb +62 -0
- data/lib/platform_helpers/parse.rb +30 -0
- data/lib/platform_helpers/string.rb +74 -0
- data/lib/platform_helpers/token.rb +21 -0
- data/lib/platform_helpers.rb +21 -0
- data/test/test_platform_helpers.rb +13 -0
- metadata +90 -0
data/.autotest
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'autotest/restart'
|
4
|
+
|
5
|
+
# Autotest.add_hook :initialize do |at|
|
6
|
+
# at.extra_files << "../some/external/dependency.rb"
|
7
|
+
#
|
8
|
+
# at.libs << ":../some/external"
|
9
|
+
#
|
10
|
+
# at.add_exception 'vendor'
|
11
|
+
#
|
12
|
+
# at.add_mapping(/dependency.rb/) do |f, _|
|
13
|
+
# at.files_matching(/test_.*rb$/)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# %w(TestA TestB).each do |klass|
|
17
|
+
# at.extra_class_map[klass] = "test/test_misc.rb"
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Autotest.add_hook :run_command do |at|
|
22
|
+
# system "rake build"
|
23
|
+
# end
|
data/.gemtest
ADDED
File without changes
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
.autotest
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
test/test_platform_helpers.rb
|
7
|
+
lib/platform_helpers.rb
|
8
|
+
lib/platform_helpers/string.rb
|
9
|
+
lib/platform_helpers/date_time.rb
|
10
|
+
lib/platform_helpers/array.rb
|
11
|
+
lib/platform_helpers/token.rb
|
12
|
+
lib/platform_helpers/fixnum.rb
|
13
|
+
lib/platform_helpers/bool.rb
|
14
|
+
lib/platform_helpers/nil.rb
|
15
|
+
lib/platform_helpers/float.rb
|
16
|
+
lib/platform_helpers/parse.rb
|
17
|
+
lib/platform_helpers/browser.rb
|
18
|
+
Rakefile
|
data/README.txt
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= platform_helpers
|
2
|
+
|
3
|
+
* http://cyberconnect.biz/opensource
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Override's some Ruby classes to add methods making for uniform calls. For example, :to_bool is common to Nil, nil, TrueClass, FalseClass, String, Float, Date, ActiveRecord::Associations::HasOneAssociation and ActiveRecord::Associations::HasManyAssociation.
|
8
|
+
|
9
|
+
There are a few compatibility features bridging the gaps between ruby1.8 and ruby1.9 as well. With the modification of String to Enumerable in ruby1.9, methods have been added so that you can grep and itterate over each line, in all ruby versions.
|
10
|
+
|
11
|
+
Code is self explanatory, for other aspects.
|
12
|
+
|
13
|
+
== LICENSE:
|
14
|
+
|
15
|
+
GPLv3: http://www.gnu.org/licenses/gpl.html
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
# Authod: Cliff Cyphers
|
8
|
+
# Published as part of the cyberconnect's platform mainly used
|
9
|
+
# in hosting rails applications.
|
10
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
11
|
+
|
12
|
+
|
13
|
+
# -*- ruby -*-
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'hoe'
|
17
|
+
|
18
|
+
# Hoe.plugin :compiler
|
19
|
+
# Hoe.plugin :gem_prelude_sucks
|
20
|
+
# Hoe.plugin :inline
|
21
|
+
# Hoe.plugin :racc
|
22
|
+
# Hoe.plugin :rubyforge
|
23
|
+
|
24
|
+
Hoe.spec 'platform_helpers' do
|
25
|
+
developer('', 'cliff.cyphers@gmail.com')
|
26
|
+
end
|
27
|
+
|
28
|
+
# vim: syntax=ruby
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class Array
|
8
|
+
=begin
|
9
|
+
def delete(search)
|
10
|
+
if search.kind_of?(Regexp)
|
11
|
+
self.each_with_index { |i, ct| self.delete_at(ct) if i =~ search }
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
=end
|
17
|
+
def pp
|
18
|
+
self.flatten
|
19
|
+
self.join(' ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_bool
|
23
|
+
length > 0 ? true : false
|
24
|
+
end
|
25
|
+
|
26
|
+
=begin
|
27
|
+
Provide compatability between ruby1.8 and ruby1.9 for :nitems by aliasing to :length.
|
28
|
+
=end
|
29
|
+
alias :nitems :length
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class TrueClass
|
8
|
+
def empty?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
def to_bool
|
12
|
+
return self
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_display(params={})
|
16
|
+
if params.has_key?(:na)
|
17
|
+
return 'NA' if params[:na].to_bool
|
18
|
+
end
|
19
|
+
return 'Yes'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class FalseClass
|
24
|
+
def empty?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
def to_bool
|
28
|
+
return self
|
29
|
+
end
|
30
|
+
def to_display(params={})
|
31
|
+
if params.has_key?(:na)
|
32
|
+
return 'NA' if params[:na].to_bool
|
33
|
+
end
|
34
|
+
return 'No'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
module Browser #:nodoc:
|
8
|
+
|
9
|
+
|
10
|
+
def self.restart_firefox(profile, proxy_port=nil)
|
11
|
+
begin
|
12
|
+
ProcessMgt.kill(Constants::BROWSER['firefox'][:app_name])
|
13
|
+
if proxy_port
|
14
|
+
Browser.backup_config('firefox', profile)
|
15
|
+
Browser.update_proxy(:name => 'firefox', :profile => profile, :port => proxy_port)
|
16
|
+
else
|
17
|
+
Browser.restore_config('firefox', profile)
|
18
|
+
end
|
19
|
+
Browser.revive('firefox')
|
20
|
+
rescue => e
|
21
|
+
$logger.error "Error restarting Firefox: #{e.inspect}"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
def self.restart_chrome(proxy_port=nil)
|
26
|
+
begin
|
27
|
+
# if Constants::PLATFORM == 'osx'
|
28
|
+
# ProcessMgt.kill(Constants::BROWSER['chrome'][:app_name])
|
29
|
+
# else
|
30
|
+
pid = ProcessMgt.pids(:search => Constants::BROWSER['chrome'][:app_name]).strip.split(' ').first
|
31
|
+
ProcessMgt.kill(:pid_list => pid)
|
32
|
+
# end
|
33
|
+
rescue => e
|
34
|
+
$logger.error "Error killing chrome: #{e.inspect}"
|
35
|
+
end
|
36
|
+
Browser.revive('chrome', proxy_port)
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.restart_ie(proxy_port=nil)
|
41
|
+
$logger.debug "Updating proxy settings for IE: #{proxy_port}"
|
42
|
+
begin
|
43
|
+
ProcessMgt.kill(Constants::BROWSER['ie'][:app_name])
|
44
|
+
ProcessMgt.kill('ieuser.exe')
|
45
|
+
rescue => e
|
46
|
+
$logger.error "killing ie -- #{e.inspect}"
|
47
|
+
end
|
48
|
+
sleep 2
|
49
|
+
if proxy_port
|
50
|
+
Browser.backup_config('ie')
|
51
|
+
Browser.update_proxy(:name => 'ie', :port => proxy_port, :host => '127.0.0.1')
|
52
|
+
else
|
53
|
+
puts "in restore from no proxy"
|
54
|
+
Browser.restore_config('ie')
|
55
|
+
end
|
56
|
+
sleep 2
|
57
|
+
Browser.revive('ie')
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
def self.is_installed?(name)
|
63
|
+
if (Constants::PLATFORM == "linux") then
|
64
|
+
return false if (name == "ie")
|
65
|
+
if Constants::BROWSER.has_key?(name)
|
66
|
+
w = `which #{Constants::BROWSER[name][:app_name]}`
|
67
|
+
if ((not ("#{w}" == "")) and (not "#{w}" =~ /\/usr\/bin\/which: no/)) then
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
else
|
72
|
+
if (Constants::PLATFORM == "osx") then
|
73
|
+
if File.exists?(Constants::BROWSER[name][:bin]) then
|
74
|
+
$logger.debug("Detected #{name} running under osx")
|
75
|
+
return true
|
76
|
+
end
|
77
|
+
else
|
78
|
+
if (Constants::PLATFORM == "windows") then
|
79
|
+
if Constants::BROWSER[name][:bin] then
|
80
|
+
$logger.debug("Detected #{name} running under windows")
|
81
|
+
return true if File.exists?(Constants::BROWSER[name][:bin])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
false
|
87
|
+
end
|
88
|
+
def self.profiles(name)
|
89
|
+
case name
|
90
|
+
when "firefox" then
|
91
|
+
p = Dir.entries(Constants::BROWSER[name][:profile_dir])
|
92
|
+
p.delete("profiles.ini")
|
93
|
+
p.delete(".")
|
94
|
+
p.delete("..")
|
95
|
+
return p
|
96
|
+
else
|
97
|
+
# do nothing
|
98
|
+
end
|
99
|
+
end
|
100
|
+
def self.backup_config(name, profile = nil)
|
101
|
+
case name
|
102
|
+
when "firefox" then
|
103
|
+
orig = (Constants::CFG[:proxy][:cfg_dir] + "/#{profile}_prefs.js.orig")
|
104
|
+
unless File.exists?(orig) then
|
105
|
+
FileUtils.cp("#{Constants::BROWSER[name][:profile_dir]}/#{profile}/prefs.js", orig)
|
106
|
+
end
|
107
|
+
when "ie" then
|
108
|
+
unless File.exists?("#{Constants::CFG[:proxy][:cfg_dir]}/ie_cfg.orig") then
|
109
|
+
begin
|
110
|
+
(reg_type, reg_val = nil
|
111
|
+
fd = File.open((Constants::CFG[:proxy][:cfg_dir] + "/ie_cfg.orig"), "w+")
|
112
|
+
fd.puts(Win32::Registry::HKEY_CURRENT_USER.open(Constants::BROWSER["ie"][:key], Win32::Registry::KEY_READ).entries.to_yaml)
|
113
|
+
fd.close)
|
114
|
+
rescue => e
|
115
|
+
$logger.error("updating windows registry: #{e.inspect}")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
else
|
119
|
+
# do nothing
|
120
|
+
end
|
121
|
+
end
|
122
|
+
def self.restore_config(name, profile = nil)
|
123
|
+
case name
|
124
|
+
when "firefox" then
|
125
|
+
if File.exists?("#{Constants::CFG[:proxy][:cfg_dir]}/#{profile}_prefs.js.orig") then
|
126
|
+
FileUtils.mv("#{Constants::CFG[:proxy][:cfg_dir]}/#{profile}_prefs.js.orig", "#{Constants::BROWSER[name][:profile_dir]}/#{profile}/prefs.js")
|
127
|
+
end
|
128
|
+
when "ie" then
|
129
|
+
$logger.debug("Updating registry for windows proxy")
|
130
|
+
if File.exists?((Constants::CFG[:proxy][:cfg_dir] + "/ie_cfg.orig")) then
|
131
|
+
begin
|
132
|
+
Win32::Registry::HKEY_CURRENT_USER.open(Constants::BROWSER["ie"][:key], Win32::Registry::KEY_WRITE) do |reg2|
|
133
|
+
reg2.write("ProxyEnable", Win32::Registry::REG_DWORD, 0)
|
134
|
+
end
|
135
|
+
rescue => e
|
136
|
+
$logger.error("updating windows registry: #{e.inspect}")
|
137
|
+
end
|
138
|
+
cfg = YAML.load_file((Constants::CFG[:proxy][:cfg_dir] + "/ie_cfg.orig"))
|
139
|
+
cfg.each do |i|
|
140
|
+
begin
|
141
|
+
Win32::Registry::HKEY_CURRENT_USER.open(Constants::BROWSER["ie"][:key], Win32::Registry::KEY_WRITE) do |reg3|
|
142
|
+
reg3.write(i[0], i[1], i[2])
|
143
|
+
end
|
144
|
+
rescue => e
|
145
|
+
$logger.error("updating windows registry: #{e.inspect}")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
begin
|
149
|
+
FileUtils.rm_f((Constants::CFG[:proxy][:cfg_dir] + "/ie_cfg.orig"))
|
150
|
+
rescue => e
|
151
|
+
$logger.error("removing ie_cfg.orig -- #{e.inspect}")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
else
|
155
|
+
# do nothing
|
156
|
+
end
|
157
|
+
end
|
158
|
+
def self.update_proxy(params = {})
|
159
|
+
params[:host] ||= "127.0.0.1"
|
160
|
+
params[:profile] ||= nil
|
161
|
+
case params[:name]
|
162
|
+
when "ie" then
|
163
|
+
begin
|
164
|
+
Browser.backup_config("ie")
|
165
|
+
rescue => e
|
166
|
+
$logger.error("backing up config from update_proxy -- #{e.inspect}")
|
167
|
+
end
|
168
|
+
begin
|
169
|
+
Win32::Registry::HKEY_CURRENT_USER.open(Constants::BROWSER["ie"][:key], Win32::Registry::KEY_WRITE) do |reg|
|
170
|
+
reg.write("ProxyEnable", Win32::Registry::REG_DWORD, 1)
|
171
|
+
end
|
172
|
+
rescue => e
|
173
|
+
puts("error updating proxy: #{e.inspect}")
|
174
|
+
$logger.error("updating windows registry: #{e.inspect}")
|
175
|
+
end
|
176
|
+
begin
|
177
|
+
Win32::Registry::HKEY_CURRENT_USER.open(Constants::BROWSER["ie"][:key], Win32::Registry::KEY_WRITE) do |reg|
|
178
|
+
reg.write("ProxyServer", Win32::Registry::REG_SZ, "#{params[:host]}:#{params[:port]}")
|
179
|
+
end
|
180
|
+
rescue => e
|
181
|
+
puts("error updating proxy: #{e.inspect}")
|
182
|
+
$logger.error("updating windows registry: #{e.inspect}")
|
183
|
+
end
|
184
|
+
when "firefox" then
|
185
|
+
prefs = File.readlines("#{Constants::BROWSER[params[:name]][:profile_dir]}/#{params[:profile]}/prefs.js")
|
186
|
+
proxy_entries = ["user_pref(\"network.proxy.ftp\", \"#{params[:host]}\");", "user_pref(\"network.proxy.ftp_port\", #{params[:port]});", "user_pref(\"network.proxy.gopher\", \"#{params[:host]}\");", "user_pref(\"network.proxy.gopher_port\", #{params[:port]});", "user_pref(\"network.proxy.http\", \"#{params[:host]}\");", "user_pref(\"network.proxy.http_port\", #{params[:port]});", "user_pref(\"network.proxy.socks\", \"#{params[:host]}\");", "user_pref(\"network.proxy.socks_port\", #{params[:port]});", "user_pref(\"network.proxy.ssl\", \"#{params[:host]}\");", "user_pref(\"network.proxy.ssl_port\", #{params[:port]});", "user_pref(\"network.proxy.type\", 1);", "user_pref(\"network.proxy.share_proxy_settings\", true);"]
|
187
|
+
prefs.each_with_index do |p, i|
|
188
|
+
if (p =~ /network\.proxy/ and ((not p =~ /network\.proxy\.backup/) and ((not p =~ /network\.proxy\.no_proxies_on/) and p =~ /_port/))) then
|
189
|
+
prefs.delete_at(i)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
prefs = (prefs + proxy_entries)
|
193
|
+
fd = File.open("#{Constants::BROWSER[params[:name]][:profile_dir]}/#{params[:profile]}/prefs.js", "w+")
|
194
|
+
prefs.each { |line| fd.puts(line) }
|
195
|
+
fd.close
|
196
|
+
end
|
197
|
+
end
|
198
|
+
def self.revive(name, proxy = nil)
|
199
|
+
ops = nil
|
200
|
+
ops = "--proxy-server=127.0.0.1:#{proxy}" if ((name == "chrome") and proxy)
|
201
|
+
if (Constants::PLATFORM == "windows") then
|
202
|
+
begin
|
203
|
+
(p = Process.create("app_name" => ("#{Constants::BROWSER[name][:bin]} #{ops}"))
|
204
|
+
Process.waitpid(p.process_id))
|
205
|
+
rescue => e
|
206
|
+
$logger.error("reviving #{name} with ops=#{ops} -- #{e.inspect}")
|
207
|
+
end
|
208
|
+
else
|
209
|
+
browser = "#{Constants::BROWSER[name][:bin].gsub(" ", "\\ ")} #{ops}"
|
210
|
+
$logger.debug("Starting browser #{name} with - #{browser}")
|
211
|
+
begin
|
212
|
+
Thread.new { `#{browser}` }
|
213
|
+
rescue => e
|
214
|
+
# do nothing
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class Date
|
8
|
+
def to_bool
|
9
|
+
if "#{self}" != ''
|
10
|
+
return true
|
11
|
+
else
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def to_us
|
16
|
+
"#{self.month}/#{self.day}/#{self.year}"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Time
|
22
|
+
def date
|
23
|
+
Date.parse("#{self.month}/#{self.day}/#{self.year}")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class Fixnum
|
8
|
+
def empty?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
def to_display(params={})
|
12
|
+
self.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class Float
|
8
|
+
def empty?
|
9
|
+
false
|
10
|
+
end
|
11
|
+
def to_display(params={})
|
12
|
+
self.to_s
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_bool
|
16
|
+
if self > 0.0
|
17
|
+
return true
|
18
|
+
else
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class Nil
|
8
|
+
def empty?
|
9
|
+
return true
|
10
|
+
end
|
11
|
+
def to_i
|
12
|
+
return 0
|
13
|
+
end
|
14
|
+
def to_f
|
15
|
+
return 0.0
|
16
|
+
end
|
17
|
+
def to_bool
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_display(params={})
|
22
|
+
if params.has_key?(:na)
|
23
|
+
if params[:na]
|
24
|
+
return 'NA'
|
25
|
+
else
|
26
|
+
return self.to_bool
|
27
|
+
end
|
28
|
+
else
|
29
|
+
return self.to_bool
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class NilClass
|
35
|
+
def empty?
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_display(params={})
|
40
|
+
if params.has_key?(:na)
|
41
|
+
if params[:na]
|
42
|
+
return 'NA'
|
43
|
+
else
|
44
|
+
return self.to_bool
|
45
|
+
end
|
46
|
+
else
|
47
|
+
return self.to_bool
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_i
|
52
|
+
return 0
|
53
|
+
end
|
54
|
+
def to_f
|
55
|
+
return 0.0
|
56
|
+
end
|
57
|
+
def to_bool
|
58
|
+
return false
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
module Parse
|
8
|
+
def self.is_comment?(line)
|
9
|
+
if line.strip.rindex('#') == 0
|
10
|
+
return true
|
11
|
+
else
|
12
|
+
return false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def self.partial_comment?(line)
|
16
|
+
if line =~ /#/
|
17
|
+
return true
|
18
|
+
else
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def self.strip_comment(line)
|
23
|
+
if partial_comment?(line)
|
24
|
+
loc = line.rindex('#')
|
25
|
+
line = line[0..loc-1]
|
26
|
+
end
|
27
|
+
line
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class String
|
8
|
+
def each
|
9
|
+
self.strip.split(' ').each { |i| yield i }
|
10
|
+
end
|
11
|
+
def each_line
|
12
|
+
self.strip.split(/\n/).each { |i| yield i }
|
13
|
+
end
|
14
|
+
|
15
|
+
def grep(i) # 1.8.x to 1.9.x compatibility
|
16
|
+
self.split(/\n/).grep(i)
|
17
|
+
end
|
18
|
+
def shift(params={})
|
19
|
+
if params.has_key?(:del)
|
20
|
+
tmp = self.split(params[:del])
|
21
|
+
tmp.delete_at(tmp.length-1)
|
22
|
+
return tmp.join(params[:del])
|
23
|
+
else
|
24
|
+
return self[0..self.length-2]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_display(params={})
|
29
|
+
if params.has_key?(:na)
|
30
|
+
return self.na if params[:na].to_bool
|
31
|
+
end
|
32
|
+
if self.to_bool
|
33
|
+
return 'Yes'
|
34
|
+
else
|
35
|
+
return 'No'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_bool(na=false)
|
40
|
+
if self =~ /^true$/i
|
41
|
+
return true
|
42
|
+
elsif self =~ /^false$/i
|
43
|
+
if na
|
44
|
+
return 'NA'
|
45
|
+
else
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
elsif self.strip == ''
|
49
|
+
return false
|
50
|
+
else
|
51
|
+
return false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def na
|
56
|
+
if self.empty?
|
57
|
+
return 'NA'
|
58
|
+
else
|
59
|
+
return self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
=begin
|
63
|
+
def to_hash
|
64
|
+
begin
|
65
|
+
raise ArgumentError, "could not parse string as hash" if "#{self}" !~ /=>/
|
66
|
+
self.gsub!(/[{}]/, '')
|
67
|
+
return eval("{#{self}}")
|
68
|
+
rescue => e
|
69
|
+
raise ArgumentError, "could not parse string as hash"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
=end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
if RUBY_VERSION =~ /1\.8/
|
8
|
+
require 'md5'
|
9
|
+
elsif RUBY_VERSION =~ /1\.9/
|
10
|
+
require 'digest/md5'
|
11
|
+
include Digest
|
12
|
+
end
|
13
|
+
module Token
|
14
|
+
def self.provide(n=10)
|
15
|
+
t=''
|
16
|
+
rand(Time.now.tv_sec)
|
17
|
+
n.times { t += "#{rand(Time.now.tv_sec)}" }
|
18
|
+
return MD5.hexdigest(t)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
class PlatformHelpers
|
8
|
+
VERSION = '0.1.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
base = File.expand_path(File.dirname(__FILE__))
|
12
|
+
require base + '/platform_helpers/array'
|
13
|
+
require base + '/platform_helpers/bool'
|
14
|
+
require base + '/platform_helpers/date_time'
|
15
|
+
require base + '/platform_helpers/fixnum'
|
16
|
+
require base + '/platform_helpers/float'
|
17
|
+
require base + '/platform_helpers/nil'
|
18
|
+
require base + '/platform_helpers/parse'
|
19
|
+
require base + '/platform_helpers/string'
|
20
|
+
require base + '/platform_helpers/token'
|
21
|
+
require base + '/platform_helpers/browser'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Authod: Cliff Cyphers
|
2
|
+
# Published as part of the cyberconnect's platform mainly used
|
3
|
+
# in hosting rails applications.
|
4
|
+
# Licesnse: GPLv3: http://www.gnu.org/licenses/gpl.html
|
5
|
+
|
6
|
+
|
7
|
+
require "test/unit"
|
8
|
+
require 'platform_helpers'
|
9
|
+
|
10
|
+
class TestWebDisplayHelpers < Test::Unit::TestCase
|
11
|
+
def test_sanity
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: platform_helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ""
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-08-22 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "2.12"
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
description: |-
|
27
|
+
Override's some Ruby classes to add methods making for uniform calls. For example, :to_bool is common to Nil, nil, TrueClass, FalseClass, String, Float, Date, ActiveRecord::Associations::HasOneAssociation and ActiveRecord::Associations::HasManyAssociation.
|
28
|
+
|
29
|
+
There are a few compatibility features bridging the gaps between ruby1.8 and ruby1.9 as well. With the modification of String to Enumerable in ruby1.9, methods have been added so that you can grep and itterate over each line, in all ruby versions.
|
30
|
+
|
31
|
+
Code is self explanatory, for other aspects.
|
32
|
+
email:
|
33
|
+
- cliff.cyphers@gmail.com
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- History.txt
|
40
|
+
- Manifest.txt
|
41
|
+
- README.txt
|
42
|
+
files:
|
43
|
+
- .autotest
|
44
|
+
- History.txt
|
45
|
+
- Manifest.txt
|
46
|
+
- README.txt
|
47
|
+
- Rakefile
|
48
|
+
- test/test_platform_helpers.rb
|
49
|
+
- lib/platform_helpers.rb
|
50
|
+
- lib/platform_helpers/string.rb
|
51
|
+
- lib/platform_helpers/date_time.rb
|
52
|
+
- lib/platform_helpers/array.rb
|
53
|
+
- lib/platform_helpers/token.rb
|
54
|
+
- lib/platform_helpers/fixnum.rb
|
55
|
+
- lib/platform_helpers/bool.rb
|
56
|
+
- lib/platform_helpers/nil.rb
|
57
|
+
- lib/platform_helpers/float.rb
|
58
|
+
- lib/platform_helpers/parse.rb
|
59
|
+
- lib/platform_helpers/browser.rb
|
60
|
+
- .gemtest
|
61
|
+
homepage: http://cyberconnect.biz/opensource
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --main
|
67
|
+
- README.txt
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: platform_helpers
|
85
|
+
rubygems_version: 1.8.8
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Override's some Ruby classes to add methods making for uniform calls
|
89
|
+
test_files:
|
90
|
+
- test/test_platform_helpers.rb
|