hobo_support 1.3.0.RC4 → 1.3.0.pre10
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/hobo_support.gemspec +1 -2
- data/lib/generators/hobo_support/model.rb +3 -4
- data/lib/generators/hobo_support/thor_shell.rb +12 -4
- data/lib/hobo_support/command.rb +44 -99
- data/lib/hobo_support/common_tasks.rb +0 -1
- data/lib/hobo_support/fixes/chronic.rb +4 -4
- data/lib/hobo_support/methodcall.rb +2 -2
- data/lib/hobo_support/methodphitamine.rb +1 -1
- data/lib/hobo_support/string.rb +4 -2
- data/lib/hobo_support.rb +0 -2
- data/test/hobosupport/module.rdoctest +2 -2
- data/test/hobosupport.rdoctest +3 -3
- metadata +27 -7
- data/lib/generators/hobo_support/eval_template.rb +0 -14
- data/test/hobosupport/chronic.rdoctest +0 -18
data/Rakefile
CHANGED
@@ -10,7 +10,7 @@ RUBYDOCTEST = ENV['RUBYDOCTEST'] || "#{RUBY} -S rubydoctest"
|
|
10
10
|
namespace "test" do
|
11
11
|
desc "Run the doctests"
|
12
12
|
task :doctest do |t|
|
13
|
-
files=Dir['test
|
13
|
+
files=Dir['test/*.rdoctest','test/hobo_support/*.rdoctest'].map {|f| File.expand_path(f)}.join(' ')
|
14
14
|
exit(1) if !system("#{RUBYDOCTEST} --single #{files}")
|
15
15
|
end
|
16
16
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.0.
|
1
|
+
1.3.0.pre10
|
data/hobo_support.gemspec
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
name = File.basename( __FILE__, '.gemspec' )
|
2
2
|
version = File.read(File.expand_path('../VERSION', __FILE__)).strip
|
3
|
-
require 'date'
|
4
3
|
|
5
4
|
Gem::Specification.new do |s|
|
6
5
|
|
@@ -11,7 +10,7 @@ Gem::Specification.new do |s|
|
|
11
10
|
s.summary = 'Core Ruby extensions from the Hobo project'
|
12
11
|
s.description = 'Core Ruby extensions from the Hobo project'
|
13
12
|
|
14
|
-
s.add_runtime_dependency('rails', ["
|
13
|
+
s.add_runtime_dependency('rails', [">= 3.0.0"])
|
15
14
|
s.add_development_dependency('rubydoctest', [">= 0"])
|
16
15
|
|
17
16
|
s.files = `git ls-files -x #{name}/* -z`.split("\0")
|
@@ -1,9 +1,6 @@
|
|
1
|
-
require 'generators/hobo_support/eval_template'
|
2
|
-
|
3
1
|
module Generators
|
4
2
|
module HoboSupport
|
5
3
|
Model = classy_module do
|
6
|
-
include EvalTemplate
|
7
4
|
|
8
5
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
9
6
|
|
@@ -18,8 +15,10 @@ module Generators
|
|
18
15
|
end
|
19
16
|
|
20
17
|
def inject_hobo_code_into_model_file
|
18
|
+
source = File.expand_path(find_in_source_paths('model_injection.rb.erb'))
|
19
|
+
context = instance_eval('binding')
|
21
20
|
inject_into_class model_path, class_name do
|
22
|
-
|
21
|
+
ERB.new(::File.binread(source), nil, '-').result(context)
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
@@ -6,14 +6,14 @@ module Generators
|
|
6
6
|
|
7
7
|
private
|
8
8
|
|
9
|
-
def ask(statement, default='', color
|
9
|
+
def ask(statement, default='', color=Thor::Shell::Color::MAGENTA)
|
10
10
|
result = super(statement, color)
|
11
11
|
result = default if result.blank?
|
12
12
|
say PREFIX + result.inspect
|
13
13
|
result
|
14
14
|
end
|
15
15
|
|
16
|
-
def yes_no?(statement, color
|
16
|
+
def yes_no?(statement, color=Thor::Shell::Color::MAGENTA)
|
17
17
|
result = choose(statement + ' [y|n]', /^(y|n)$/i)
|
18
18
|
result == 'y' ? true : false
|
19
19
|
end
|
@@ -26,8 +26,8 @@ module Generators
|
|
26
26
|
when choice.blank? && !default.blank?
|
27
27
|
default
|
28
28
|
else
|
29
|
-
say 'Unknown choice! ',
|
30
|
-
choose(prompt, format
|
29
|
+
say 'Unknown choice! ', Thor::Shell::Color::RED
|
30
|
+
choose(prompt, format)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,6 +35,14 @@ module Generators
|
|
35
35
|
say "\n #{title} \n", "\e[37;44m"
|
36
36
|
end
|
37
37
|
|
38
|
+
def multi_ask(statement)
|
39
|
+
result = []
|
40
|
+
while (r = ask(statement)) && !r.blank?
|
41
|
+
result << r
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
data/lib/hobo_support/command.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'tmpdir'
|
3
2
|
|
4
3
|
module HoboSupport
|
5
4
|
module Command
|
@@ -10,138 +9,84 @@ module HoboSupport
|
|
10
9
|
is_hobo = gem == :hobo
|
11
10
|
puts "#{gem.to_s.capitalize} Command Line Interface #{version}"
|
12
11
|
|
13
|
-
|
14
|
-
Usage:
|
15
|
-
|
16
|
-
|
17
|
-
--
|
18
|
-
--setup launch the setup_wizard in non-interactive mode
|
19
|
-
expect you pass other setup_wizard options
|
20
|
-
--skip-setup generate only the rails infrastructure and
|
21
|
-
expect you launch the setup_wizard manually
|
22
|
-
rails_opt: all the options accepted by the rails command
|
23
|
-
)
|
12
|
+
banner = %(
|
13
|
+
Usage:
|
14
|
+
hobo new <app_name> [rails_options] Creates a new Hobo Application
|
15
|
+
hobo g <generator> [ARGS] [options] Fires the hobo:<generator>
|
16
|
+
hobo --help This help screen
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
)
|
18
|
+
Dev Notes:
|
19
|
+
Set the HOBO_DEV_ROOT ENV variable to the Hobo root path in order
|
20
|
+
to use your local dev version instead of the installed gem.
|
29
21
|
|
30
|
-
|
31
|
-
banner += %(
|
32
|
-
#{gem} generate|g <generator> [ARGS] [options] Fires the hobo:<generator>
|
33
|
-
#{gem} destroy <generator> [ARGS] [options] Tries to undo generated code
|
34
|
-
|
35
|
-
#{gem} --help|-h This help screen
|
36
|
-
|
37
|
-
Dev Notes:
|
38
|
-
Set the HOBODEV ENV variable to your local hobo git-repository path
|
39
|
-
in order to use your local dev version instead of the installed gem.
|
40
|
-
|
41
|
-
)
|
42
|
-
|
43
|
-
# for hobo developers only
|
44
|
-
setup_wizard = true
|
45
|
-
default = false
|
22
|
+
)
|
46
23
|
|
47
24
|
command = ARGV.shift
|
48
|
-
|
49
|
-
case command
|
50
|
-
|
51
|
-
when nil
|
25
|
+
if command.nil?
|
52
26
|
puts "\nThe command is missing!\n"
|
53
27
|
puts banner
|
54
28
|
exit
|
29
|
+
end
|
30
|
+
# for hobo developers only
|
31
|
+
setup_wizard = true
|
55
32
|
|
56
|
-
|
57
|
-
puts banner
|
58
|
-
exit
|
33
|
+
case command
|
59
34
|
|
60
35
|
when 'new'
|
61
36
|
app_name = ARGV.shift
|
37
|
+
if is_hobo && ARGV.first =~ /^--skip-wizard$/
|
38
|
+
setup_wizard = false
|
39
|
+
ARGV.shift
|
40
|
+
end
|
62
41
|
if app_name.nil?
|
63
42
|
puts "\nThe application name is missing!\n"
|
64
43
|
puts banner
|
65
44
|
exit
|
66
45
|
end
|
67
|
-
|
68
|
-
setup_wizard = case ARGV.first
|
69
|
-
when /^--skip-wizard|--skip-setup$/
|
70
|
-
ARGV.shift
|
71
|
-
:skip
|
72
|
-
when /^--setup|--default$/
|
73
|
-
ARGV.shift
|
74
|
-
:setup
|
75
|
-
when /^--wizard$/
|
76
|
-
ARGV.shift
|
77
|
-
:wizard
|
78
|
-
else
|
79
|
-
:wizard
|
80
|
-
end
|
81
|
-
end
|
82
|
-
template_path = File.join Dir.tmpdir, "hobo_app_template"
|
46
|
+
template_path = "/tmp/hobo_app_template"
|
83
47
|
File.open(template_path, 'w') do |file|
|
84
|
-
if ENV["
|
85
|
-
dev_root = File.expand_path ENV["
|
48
|
+
if ENV["HOBO_DEV_ROOT"]
|
49
|
+
dev_root = File.expand_path ENV["HOBO_DEV_ROOT"], FileUtils.pwd
|
86
50
|
file.puts %(
|
87
|
-
$:.unshift '#{dev_root}/hobo_support/lib'
|
88
|
-
gem 'hobo_support', :path => '#{dev_root}/hobo_support'
|
89
|
-
gem 'hobo_fields', :path => '#{dev_root}/hobo_fields'
|
90
|
-
)
|
51
|
+
$:.unshift '#{dev_root}/hobo_support/lib'
|
52
|
+
gem 'hobo_support', :path => '#{dev_root}/hobo_support'
|
53
|
+
gem 'hobo_fields', :path => '#{dev_root}/hobo_fields'
|
54
|
+
)
|
91
55
|
if is_hobo
|
92
56
|
file.puts %(
|
93
|
-
gem 'dryml', :path => '#{dev_root}/dryml'
|
94
|
-
gem 'hobo', :path => '#{dev_root}/hobo'
|
95
|
-
)
|
57
|
+
gem 'dryml', :path => '#{dev_root}/dryml'
|
58
|
+
gem 'hobo', :path => '#{dev_root}/hobo'
|
59
|
+
)
|
96
60
|
end
|
97
61
|
else
|
98
|
-
file.puts
|
99
|
-
gem '#{gem}', '= #{version}'
|
100
|
-
)
|
62
|
+
file.puts "gem '#{gem}', '>= #{version}'"
|
101
63
|
end
|
102
|
-
if is_hobo
|
64
|
+
if is_hobo && setup_wizard
|
103
65
|
file.puts %(
|
104
|
-
require 'generators/hobo_support/thor_shell'
|
105
|
-
extend Generators::HoboSupport::ThorShell
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
exec 'rails g hobo:setup_wizard --
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
if yes_no?("Do you want to start the Setup Wizard now?
|
117
|
-
(Choose 'n' if you need to manually customize any file before running the Wizard.
|
118
|
-
You can run it later with `hobo g setup_wizard` from the application root dir.)")
|
119
|
-
exec 'rails g hobo:setup_wizard --no-main-title'
|
120
|
-
else
|
121
|
-
say "Please, remember to run `hobo g setup_wizard` from the application root dir, in order to complete the Setup.", :yellow
|
122
|
-
end
|
123
|
-
)
|
124
|
-
when :skip
|
125
|
-
file.puts %(
|
126
|
-
say "Please, remember to run `hobo g setup_wizard` from the application root dir, in order to complete the Setup.", :yellow
|
127
|
-
)
|
128
|
-
end
|
66
|
+
require 'generators/hobo_support/thor_shell'
|
67
|
+
extend Generators::HoboSupport::ThorShell
|
68
|
+
|
69
|
+
say_title "Hobo Setup Wizard"
|
70
|
+
if yes_no?("Do you want to start the Setup Wizard now?
|
71
|
+
(Choose 'no' if you need to manually customize any file before running the Wizard.
|
72
|
+
You can rerun it at any time with `hobo g setup_wizard` from the application root dir.)")
|
73
|
+
exec 'rails g hobo:setup_wizard --no-main-title'
|
74
|
+
else
|
75
|
+
say "Please, remember to run `hobo g setup_wizard` from the application root dir, in order to complete the Setup.", Thor::Shell::Color::YELLOW
|
76
|
+
end
|
77
|
+
)
|
129
78
|
end
|
130
79
|
end
|
131
80
|
puts "Generating Rails infrastructure..."
|
132
81
|
system "rails new #{app_name} #{ARGV * ' '} -m #{template_path}"
|
133
82
|
File.delete template_path
|
134
83
|
|
135
|
-
when /^(g|generate
|
136
|
-
cmd = $1
|
84
|
+
when /^(g|generate)$/
|
137
85
|
if ARGV.empty?
|
138
86
|
puts "\nThe generator name is missing!\n"
|
139
87
|
puts banner
|
140
88
|
else
|
141
|
-
|
142
|
-
puts "NOTICE: You can omit the 'hobo' namespace: e.g. `hobo #{cmd} #{$1} #{ARGV[1..-1] * ' '}`"
|
143
|
-
end
|
144
|
-
system "rails #{cmd} hobo:#{ARGV * ' '}"
|
89
|
+
exec "rails g hobo:#{ARGV * ' '}"
|
145
90
|
end
|
146
91
|
|
147
92
|
else
|
@@ -5,15 +5,15 @@ begin
|
|
5
5
|
module Chronic
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def parse_with_hobo_fix(s
|
9
|
-
if s =~ /^\s*\d+\s*(st|nd|rd|th)\s+[a-zA-Z]+(\s+\d+)?\s*$/
|
8
|
+
def parse_with_hobo_fix(s)
|
9
|
+
if s =~ /^\s*\d+\s*(st|nd|rd|th)\s+[a-zA-Z]+(\s+\d+)?\s*$/
|
10
10
|
s = s.sub(/\s*\d+(st|nd|rd|th)/) {|s| s[0..-3]}
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
# Chronic can't parse '1/1/2008 1:00' or '1/1/2008 1:00 PM',
|
14
14
|
# so convert them to '1/1/2008 @ 1:00' and '1/1/2008 @ 1:00 PM'
|
15
15
|
s = s.sub(/^\s*(\d+\/\d+\/\d+)\s+(\d+:\d+.*)/, '\1 @ \2')
|
16
|
-
parse_without_hobo_fix(s
|
16
|
+
parse_without_hobo_fix(s)
|
17
17
|
end
|
18
18
|
alias_method_chain :parse, :hobo_fix
|
19
19
|
end
|
data/lib/hobo_support/string.rb
CHANGED
@@ -22,7 +22,9 @@ class String
|
|
22
22
|
def safe_constantize
|
23
23
|
Object.class_eval self
|
24
24
|
rescue NameError => e
|
25
|
-
|
25
|
+
# Unfortunately we have to rely on the error message to figure out which constant was missing.
|
26
|
+
# NameError has a #name method but it is always nil
|
27
|
+
if e.message !~ /\b#{self}$/
|
26
28
|
# oops - some other name error
|
27
29
|
raise
|
28
30
|
else
|
@@ -31,4 +33,4 @@ class String
|
|
31
33
|
end
|
32
34
|
|
33
35
|
|
34
|
-
end
|
36
|
+
end
|
data/lib/hobo_support.rb
CHANGED
@@ -21,7 +21,7 @@ When a module is included in a class, it gets a callback on the `included` metho
|
|
21
21
|
alias_method_chain :name, :shouting
|
22
22
|
end
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
25
25
|
|
26
26
|
module M1
|
27
27
|
def self.included(base)
|
@@ -76,7 +76,7 @@ In Ruby we use modules to factor out features that are shared by more than one c
|
|
76
76
|
module M
|
77
77
|
def self.included(base)
|
78
78
|
base.send(:extend, ClassMethods)
|
79
|
-
end
|
79
|
+
end
|
80
80
|
|
81
81
|
module ClassMethods
|
82
82
|
def foo; 123; end
|
data/test/hobosupport.rdoctest
CHANGED
@@ -7,17 +7,17 @@ HoboSupport is a mixed bag of core ruby extensions that have been extracted from
|
|
7
7
|
doctest_require: '../lib/hobo_support'
|
8
8
|
{.hidden}
|
9
9
|
|
10
|
+
>> HoboSupport::VERSION
|
11
|
+
=> "1.3.0.pre6"
|
10
12
|
|
11
13
|
## Contents
|
12
14
|
|
13
|
-
* [Chronic](/manual/hobo_support/chronic)
|
14
15
|
* [Enumerable](/manual/hobo_support/enumerable)
|
15
16
|
* [Hash](/manual/hobo_support/hash)
|
16
17
|
* [Implies](/manual/hobo_support/implies)
|
17
18
|
* [Metaid](/manual/hobo_support/metaid)
|
18
19
|
* [Methodphitamine](/manual/hobo_support/methodphitamine)
|
19
20
|
* [Module](/manual/hobo_support/module)
|
20
|
-
* [XSS](/manual/hobo_support/xss)
|
21
21
|
|
22
22
|
## Object extensions
|
23
23
|
|
@@ -34,7 +34,7 @@ Like `is_a?` but multiple types to be checked in one go
|
|
34
34
|
|
35
35
|
## Method call extensions
|
36
36
|
|
37
|
-
We have the "." operator to call methods on objects. These extensions introduce two "special dots".
|
37
|
+
We have the "." operator to call methods on objects. These extensions introduce two "special dots".
|
38
38
|
|
39
39
|
### `Object#_?`
|
40
40
|
|
metadata
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobo_support
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: -1637175975
|
5
|
+
prerelease: true
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
- pre10
|
11
|
+
version: 1.3.0.pre10
|
6
12
|
platform: ruby
|
7
13
|
authors:
|
8
14
|
- Tom Locke
|
@@ -10,7 +16,7 @@ autorequire:
|
|
10
16
|
bindir: bin
|
11
17
|
cert_chain: []
|
12
18
|
|
13
|
-
date:
|
19
|
+
date: 2010-10-10 00:00:00 -04:00
|
14
20
|
default_executable:
|
15
21
|
dependencies:
|
16
22
|
- !ruby/object:Gem::Dependency
|
@@ -19,8 +25,13 @@ dependencies:
|
|
19
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
26
|
none: false
|
21
27
|
requirements:
|
22
|
-
- -
|
28
|
+
- - ">="
|
23
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 7
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
- 0
|
24
35
|
version: 3.0.0
|
25
36
|
type: :runtime
|
26
37
|
version_requirements: *id001
|
@@ -32,6 +43,9 @@ dependencies:
|
|
32
43
|
requirements:
|
33
44
|
- - ">="
|
34
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 3
|
47
|
+
segments:
|
48
|
+
- 0
|
35
49
|
version: "0"
|
36
50
|
type: :development
|
37
51
|
version_requirements: *id002
|
@@ -49,7 +63,6 @@ files:
|
|
49
63
|
- Rakefile
|
50
64
|
- VERSION
|
51
65
|
- hobo_support.gemspec
|
52
|
-
- lib/generators/hobo_support/eval_template.rb
|
53
66
|
- lib/generators/hobo_support/model.rb
|
54
67
|
- lib/generators/hobo_support/thor_shell.rb
|
55
68
|
- lib/hobo_support.rb
|
@@ -71,7 +84,6 @@ files:
|
|
71
84
|
- lib/hobo_support/string.rb
|
72
85
|
- lib/hobo_support/xss.rb
|
73
86
|
- test/hobosupport.rdoctest
|
74
|
-
- test/hobosupport/chronic.rdoctest
|
75
87
|
- test/hobosupport/enumerable.rdoctest
|
76
88
|
- test/hobosupport/hash.rdoctest
|
77
89
|
- test/hobosupport/implies.rdoctest
|
@@ -93,17 +105,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
105
|
requirements:
|
94
106
|
- - ">="
|
95
107
|
- !ruby/object:Gem::Version
|
108
|
+
hash: 3
|
109
|
+
segments:
|
110
|
+
- 0
|
96
111
|
version: "0"
|
97
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
113
|
none: false
|
99
114
|
requirements:
|
100
115
|
- - ">="
|
101
116
|
- !ruby/object:Gem::Version
|
117
|
+
hash: 23
|
118
|
+
segments:
|
119
|
+
- 1
|
120
|
+
- 3
|
121
|
+
- 6
|
102
122
|
version: 1.3.6
|
103
123
|
requirements: []
|
104
124
|
|
105
125
|
rubyforge_project: hobo
|
106
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.3.7
|
107
127
|
signing_key:
|
108
128
|
specification_version: 3
|
109
129
|
summary: Core Ruby extensions from the Hobo project
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Generators
|
2
|
-
module HoboSupport
|
3
|
-
EvalTemplate = classy_module do
|
4
|
-
|
5
|
-
private
|
6
|
-
def eval_template(template_name)
|
7
|
-
source = File.expand_path(find_in_source_paths(template_name))
|
8
|
-
context = instance_eval('binding')
|
9
|
-
ERB.new(::File.binread(source), nil, '-').result(context)
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# HoboSupport - Chronic extensions
|
2
|
-
|
3
|
-
doctest_require: '../../lib/hobo_support'
|
4
|
-
{.hidden}
|
5
|
-
|
6
|
-
## `Chronic.parse`
|
7
|
-
|
8
|
-
Chronic.parse can't parse 'M/D/Y H:S', so convert it to 'M/D/Y @ H:S'.
|
9
|
-
|
10
|
-
>> Chronic.parse('1/1/2008 1:00') == Chronic.parse('1/1/2008 @ 1:00')
|
11
|
-
|
12
|
-
=> true
|
13
|
-
|
14
|
-
Chronic.parse takes additional options (see Chronic.parse).
|
15
|
-
|
16
|
-
>> Chronic.parse('today', :guess => false).instance_of? Chronic::Span
|
17
|
-
|
18
|
-
=> true
|