hobo_support 1.3.0.RC

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 0.1
2
+
3
+ * First release as a separate gem
4
+
5
+
data/README.txt ADDED
@@ -0,0 +1,36 @@
1
+ = hobo_support
2
+
3
+ * http://hobocentral.net/hobo_support
4
+
5
+ == DESCRIPTION:
6
+
7
+ A mixed bag of core Ruby extenstion that have been extracted from the Hobo project.
8
+
9
+ == INSTALL:
10
+
11
+ * sudo gem install hobo_support
12
+
13
+ == LICENSE:
14
+
15
+ (The MIT License)
16
+
17
+ Copyright (c) 2008 Tom Locke
18
+
19
+ Permission is hereby granted, free of charge, to any person obtaining
20
+ a copy of this software and associated documentation files (the
21
+ 'Software'), to deal in the Software without restriction, including
22
+ without limitation the rights to use, copy, modify, merge, publish,
23
+ distribute, sublicense, and/or sell copies of the Software, and to
24
+ permit persons to whom the Software is furnished to do so, subject to
25
+ the following conditions:
26
+
27
+ The above copyright notice and this permission notice shall be
28
+ included in all copies or substantial portions of the Software.
29
+
30
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
31
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
34
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
35
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
36
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'active_record'
2
+ ActiveRecord::ActiveRecordError # hack for https://rails.lighthouseapp.com/projects/8994/tickets/2577-when-using-activerecordassociations-outside-of-rails-a-nameerror-is-thrown
3
+
4
+ $:.unshift File.expand_path( '../lib', __FILE__)
5
+ require 'hobo_support'
6
+
7
+ RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).sub(/.*\s.*/m, '"\&"')
8
+ RUBYDOCTEST = ENV['RUBYDOCTEST'] || "#{RUBY} -S rubydoctest"
9
+
10
+ namespace "test" do
11
+ desc "Run the doctests"
12
+ task :doctest do |t|
13
+ files=Dir['test/**/*.rdoctest'].map {|f| File.expand_path(f)}.join(' ')
14
+ exit(1) if !system("#{RUBYDOCTEST} --single #{files}")
15
+ end
16
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.3.0.RC
@@ -0,0 +1,29 @@
1
+ name = File.basename( __FILE__, '.gemspec' )
2
+ version = File.read(File.expand_path('../VERSION', __FILE__)).strip
3
+ require 'date'
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.authors = ['Tom Locke']
8
+ s.email = 'tom@tomlocke.com'
9
+ s.homepage = 'http://hobocentral.net'
10
+ s.rubyforge_project = 'hobo'
11
+ s.summary = 'Core Ruby extensions from the Hobo project'
12
+ s.description = 'Core Ruby extensions from the Hobo project'
13
+
14
+ s.add_runtime_dependency('rails', ["~> 3.0.0"])
15
+ s.add_development_dependency('rubydoctest', [">= 0"])
16
+
17
+ s.files = `git ls-files -x #{name}/* -z`.split("\0")
18
+
19
+ s.name = name
20
+ s.version = version
21
+ s.date = Date.today.to_s
22
+
23
+ s.required_rubygems_version = ">= 1.3.6"
24
+ s.rdoc_options = ["--charset=UTF-8"]
25
+ s.require_paths = ["lib"]
26
+
27
+ end
28
+
29
+
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,50 @@
1
+ require 'generators/hobo_support/eval_template'
2
+
3
+ module Generators
4
+ module HoboSupport
5
+ Model = classy_module do
6
+ include EvalTemplate
7
+
8
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
9
+
10
+ def self.banner
11
+ "rails generate hobo:model #{self.arguments.map(&:usage).join(' ')} [options]"
12
+ end
13
+
14
+ class_option :timestamps, :type => :boolean
15
+
16
+ def generate_model
17
+ invoke "active_record:model", [name], {:migration => false}.merge(options)
18
+ end
19
+
20
+ def inject_hobo_code_into_model_file
21
+ inject_into_class model_path, class_name do
22
+ eval_template('model_injection.rb.erb')
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def model_path
29
+ @model_path ||= File.join("app", "models", "#{file_path}.rb")
30
+ end
31
+
32
+ def max_attribute_length
33
+ attributes.*.name.*.length.max
34
+ end
35
+
36
+ def field_attributes
37
+ attributes.reject { |a| a.name == "bt" || a.name == "hm" }
38
+ end
39
+
40
+ def hms
41
+ attributes.select { |a| a.name == "hm" }.*.type
42
+ end
43
+
44
+ def bts
45
+ attributes.select { |a| a.name == "bt" }.*.type
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ module Generators
2
+ module HoboSupport
3
+ module ThorShell
4
+
5
+ PREFIX = ' => '
6
+
7
+ private
8
+
9
+ def ask(statement, default='', color=:magenta)
10
+ result = super(statement, color)
11
+ result = default if result.blank?
12
+ say PREFIX + result.inspect
13
+ result
14
+ end
15
+
16
+ def yes_no?(statement, color=:magenta)
17
+ result = choose(statement + ' [y|n]', /^(y|n)$/i)
18
+ result == 'y' ? true : false
19
+ end
20
+
21
+ def choose(prompt, format, default=nil)
22
+ choice = ask prompt, default
23
+ case
24
+ when choice =~ format
25
+ choice
26
+ when choice.blank? && !default.blank?
27
+ default
28
+ else
29
+ say 'Unknown choice! ', :red
30
+ choose(prompt, format)
31
+ end
32
+ end
33
+
34
+ def say_title(title)
35
+ say "\n #{title} \n", "\e[37;44m"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'active_support/dependencies'
4
+
5
+ require "hobo_support/fixes/chronic"
6
+ require "hobo_support/fixes/pp"
7
+ require "hobo_support/fixes/module"
8
+ require 'hobo_support/blankslate'
9
+ require 'hobo_support/methodcall'
10
+ require 'hobo_support/methodphitamine'
11
+ require 'hobo_support/metaid'
12
+ require 'hobo_support/implies'
13
+ require 'hobo_support/enumerable'
14
+ require 'hobo_support/array'
15
+ require 'hobo_support/hash'
16
+ require 'hobo_support/module'
17
+ require 'hobo_support/string'
18
+ require 'hobo_support/xss'
19
+ require 'hobo_support/kernel'
20
+
21
+ module HoboSupport
22
+
23
+ VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
24
+
25
+ end
@@ -0,0 +1,40 @@
1
+ class Array
2
+
3
+ alias_method :multiply, :*
4
+
5
+ def *(rhs=nil)
6
+ if rhs
7
+ multiply(rhs)
8
+ else
9
+ Enumerable::MultiSender.new(self, :map)
10
+ end
11
+ end
12
+
13
+ def drop_while!
14
+ drop = 0
15
+ drop += 1 while yield(self[drop])
16
+ self[0..drop-1] = []
17
+ self
18
+ end
19
+
20
+ # useful function from Rails 2.3
21
+ if !respond_to? :wrap
22
+ def self.wrap(object)
23
+ case object
24
+ when nil
25
+ []
26
+ when self
27
+ object
28
+ else
29
+ if object.respond_to?(:to_ary)
30
+ object.to_ary
31
+ else
32
+ [object]
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+
@@ -0,0 +1,13 @@
1
+ # Define BlankSlate in case ActiveSupport aint present
2
+ unless defined? BlankSlate
3
+ unless defined? BlankSlate
4
+ class BlankSlate
5
+ instance_methods.reject { |m| m =~ /^__/ || m =~ /^(object_id|instance_eval)$/ }.each { |m| undef_method m }
6
+ def initialize(me)
7
+ @me = me
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+
@@ -0,0 +1,156 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ module HoboSupport
5
+ module Command
6
+ class << self
7
+
8
+ def run(gem, version=nil)
9
+ version ||= File.read(File.expand_path('../../../VERSION', __FILE__)).strip
10
+ is_hobo = gem == :hobo
11
+ puts "#{gem.to_s.capitalize} Command Line Interface #{version}"
12
+
13
+ hobo_banner = %(
14
+ Usage:
15
+ hobo new <app_name> [setup_opt] [rails_opt] Creates a new Hobo Application
16
+ setup_opt:
17
+ --wizard|<none> launch the setup_wizard in interactive mode
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
+ )
24
+
25
+ hobofields_banner = %(
26
+ Usage:
27
+ hobofields new <app_name> [rails_opt] Creates a new HoboFields Application
28
+ )
29
+
30
+ banner = is_hobo ? hobo_banner : hobofields_banner
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
46
+
47
+ command = ARGV.shift
48
+
49
+ case command
50
+
51
+ when nil
52
+ puts "\nThe command is missing!\n"
53
+ puts banner
54
+ exit
55
+
56
+ when /^--help|-h$/
57
+ puts banner
58
+ exit
59
+
60
+ when 'new'
61
+ app_name = ARGV.shift
62
+ if app_name.nil?
63
+ puts "\nThe application name is missing!\n"
64
+ puts banner
65
+ exit
66
+ end
67
+ if is_hobo
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"
83
+ File.open(template_path, 'w') do |file|
84
+ if ENV["HOBODEV"]
85
+ dev_root = File.expand_path ENV["HOBODEV"], FileUtils.pwd
86
+ 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
+ )
91
+ if is_hobo
92
+ file.puts %(
93
+ gem 'dryml', :path => '#{dev_root}/dryml'
94
+ gem 'hobo', :path => '#{dev_root}/hobo'
95
+ )
96
+ end
97
+ else
98
+ file.puts %(
99
+ gem '#{gem}', '>= #{version}'
100
+ )
101
+ end
102
+ if is_hobo
103
+ file.puts %(
104
+ require 'generators/hobo_support/thor_shell'
105
+ extend Generators::HoboSupport::ThorShell
106
+ )
107
+ case setup_wizard
108
+ when :setup
109
+ file.puts %(
110
+ say 'Running Setup...'
111
+ exec 'rails g hobo:setup_wizard --skip-wizard #{ARGV * ' '} '
112
+ )
113
+ when :wizard
114
+ file.puts %(
115
+ say_title "Hobo Setup Wizard"
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
129
+ end
130
+ end
131
+ puts "Generating Rails infrastructure..."
132
+ system "rails new #{app_name} #{ARGV * ' '} -m #{template_path}"
133
+ File.delete template_path
134
+
135
+ when /^(g|generate|destroy)$/
136
+ cmd = $1
137
+ if ARGV.empty?
138
+ puts "\nThe generator name is missing!\n"
139
+ puts banner
140
+ else
141
+ if ARGV.first =~ /^hobo:(\w+)$/
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 * ' '}"
145
+ end
146
+
147
+ else
148
+ puts "\n => '#{command}' is an unknown command!\n"
149
+ puts banner
150
+ end
151
+
152
+ end
153
+
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,33 @@
1
+ require 'hobo_support/module'
2
+
3
+ module HoboSupport
4
+ CommonTasks = classy_module do
5
+
6
+ namespace :test do
7
+ desc "Run the irt tests"
8
+ task :irt => :prepare_testapp do |t|
9
+ chdir TESTAPP_PATH
10
+ sh %(irt #{File.expand_path('.',GEM_ROOT)})
11
+ end
12
+
13
+ desc "Prepare a rails application for testing"
14
+ task :prepare_testapp, :force do |t, args|
15
+ if args.force || !File.directory?(TESTAPP_PATH)
16
+ remove_entry_secure( TESTAPP_PATH, true )
17
+ sh %(#{BIN} new #{TESTAPP_PATH} --skip-wizard)
18
+ chdir TESTAPP_PATH
19
+ sh %(echo "gem 'irt', :group => :console" >> Gemfile) # to make the bundler happy
20
+ sh %(echo "" > app/models/.gitignore) # because git reset --hard would rm the dir
21
+ rm %(.gitignore) # we need to reset everything in a testapp
22
+ sh %(git init && git add . && git commit -m "initial commit")
23
+ puts %(The testapp has been created in '#{TESTAPP_PATH}')
24
+ else
25
+ chdir TESTAPP_PATH
26
+ sh %(git add .)
27
+ sh %(git reset --hard -q HEAD)
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end