Class: Jeweler::Generator
- Inherits:
-
Object
- Object
- Jeweler::Generator
- Defined in:
- lib/bio-gem/mod/jeweler.rb,
lib/bio-gem/mod/jeweler/options.rb,
lib/bio-gem/mod/jeweler/github_mixin.rb
Defined Under Namespace
Modules: GithubMixin Classes: Options
Instance Method Summary collapse
- #bin_dir ⇒ Object
- #bin_name ⇒ Object
- #create_and_push_repo ⇒ Object
- #create_db_structure ⇒ Object
-
#create_files ⇒ Object
this is the default directory for storing library datasets creates a data directory for every needs.
- #db_dir ⇒ Object
- #engine_dirs ⇒ Object
- #engine_filename ⇒ Object
- #engine_module_name ⇒ Object
- #engine_name ⇒ Object
- #engine_name_prefix ⇒ Object
- #engine_namespace ⇒ Object
- #exists_dir?(dir) ⇒ Boolean
-
#initialize(options = {}) ⇒ Generator
constructor
A new instance of Generator.
- #lib_dir ⇒ Object
- #lib_filename ⇒ Object
- #lib_sub_module ⇒ Object
- #original_create_files ⇒ Object
- #original_initialize ⇒ Object
- #original_project_name ⇒ Object
- #output_template_in_target_generic(source, destination = source, template_dir = template_dir_biogem, write_type = 'w') ⇒ Object
- #output_template_in_target_generic_update(source, destination = source, template_dir = template_dir_biogem) ⇒ Object
- #project_name ⇒ Object
- #puts_template_message(message, length = 70, padding = 4) ⇒ Object
- #render_template_generic(source, template_dir = template_dir_biogem) ⇒ Object
- #require_name ⇒ Object
- #sub_module ⇒ Object
- #target_dir ⇒ Object (also: #github_repo_name)
- #template_dir_biogem ⇒ Object
- #test_data_dir ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Generator
Returns a new instance of Generator.
20 21 22 23 24 25 26 27 28 |
# File 'lib/bio-gem/mod/jeweler.rb', line 20 def initialize( = {}) original_initialize() development_dependencies << ["bio", ">= 1.4.2"] if [:biogem_db] development_dependencies << ["activerecord", ">= 3.0.7"] development_dependencies << ["activesupport", ">= 3.0.7"] development_dependencies << ["sqlite3", ">= 1.3.3"] end end |
Instance Method Details
#bin_dir ⇒ Object
61 62 63 |
# File 'lib/bio-gem/mod/jeweler.rb', line 61 def bin_dir 'bin' end |
#bin_name ⇒ Object
65 66 67 |
# File 'lib/bio-gem/mod/jeweler.rb', line 65 def bin_name "bio#{original_project_name}" end |
#create_and_push_repo ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/bio-gem/mod/jeweler.rb', line 209 def create_and_push_repo begin Net::HTTP.post_form URI.parse('http://github.com/api/v2/yaml/repos/create'), 'login' => github_username, 'token' => github_token, 'description' => summary, 'name' => github_repo_name # BY DEFAULT THE REPO IS CREATED # DO NOT PUSH THE REPO BECAUSE USER MUST ADD INFO TO CONFIGURATION FILES # TODO do a HEAD request to see when it's ready? #@repo.push('origin') rescue SocketError => se ("Seems you are not connected to Internet, can't create a remote repository. Do not forget to create it by hand, from GitHub, and sync it with this project.") end end |
#create_db_structure ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/bio-gem/mod/jeweler.rb', line 139 def create_db_structure migrate_dir = File.join(db_dir, "migrate") mkdir_in_target(db_dir) mkdir_in_target(migrate_dir) mkdir_in_target("config") unless exists_dir?("config") mkdir_in_target("lib/bio") mkdir_in_target(lib_sub_module) output_template_in_target_generic 'database', File.join("config", "database.yml") output_template_in_target_generic 'migration', File.join(migrate_dir, "001_create_example.rb" ) output_template_in_target_generic 'seeds', File.join(db_dir, "seeds.rb") output_template_in_target_generic 'rakefile', 'Rakefile', template_dir_biogem, 'a' #need to spec all the option to enable the append option #TODO I'd like to have a parameter from command like with defines the Namespace of the created bio-gem to automatically costruct directory structure output_template_in_target_generic 'db_connection', File.join(lib_sub_module,"connect.rb") output_template_in_target_generic 'db_model', File.join(lib_sub_module,"example.rb") end |
#create_files ⇒ Object
this is the default directory for storing library datasets creates a data directory for every needs. the options are defined in mod/jeweler/options.rb
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/bio-gem/mod/jeweler.rb', line 159 def create_files if [:biogem_meta] unless File.exists?(target_dir) || File.directory?(target_dir) FileUtils.mkdir target_dir else raise FileInTheWay, "The directory #{target_dir} already exists, aborting. Maybe move it out of the way before continuing?" end output_template_in_target '.gitignore' output_template_in_target 'Rakefile' output_template_in_target 'Gemfile' if should_use_bundler output_template_in_target 'LICENSE.txt' output_template_in_target 'README.rdoc' output_template_in_target '.document' else original_create_files if [:biogem_test_data] mkdir_in_target("test") unless File.exists? "#{target_dir}/test" mkdir_in_target test_data_dir end create_db_structure if [:biogem_db] if [:biogem_bin] mkdir_in_target bin_dir output_template_in_target_generic 'bin', File.join(bin_dir, bin_name) # TODO: set the file as executable File.chmod 0655, File.join(target_dir, bin_dir, bin_name) end # Fill lib/bio-plugin.rb with some default comments output_template_in_target_generic 'lib', File.join(lib_dir, lib_filename) #creates the strutures and files needed to have a ready to go Rails' engine if namespace=[:biogem_engine] engine_dirs.each do |dir| mkdir_in_target(dir) unless exists_dir?(dir) end output_template_in_target_generic 'engine', File.join('lib', engine_filename ) output_template_in_target_generic_update 'library', File.join('lib', lib_filename) output_template_in_target_generic 'routes', File.join('config', "routes.rb" ) output_template_in_target_generic 'foos_controller', File.join('app',"controllers", "foos_controller.rb" ) output_template_in_target_generic 'foos_view_index', File.join('app',"views","foos", "index.html.erb" ) output_template_in_target_generic 'foos_view_show', File.join('app',"views","foos", "show.html.erb" ) output_template_in_target_generic 'foos_view_example', File.join('app',"views","foos", "example.html.erb" ) output_template_in_target_generic 'foos_view_new', File.join('app',"views","foos", "new.html.erb" ) end end #not_bio_gem_meta end |
#db_dir ⇒ Object
57 58 59 |
# File 'lib/bio-gem/mod/jeweler.rb', line 57 def db_dir 'db' end |
#engine_dirs ⇒ Object
69 70 71 |
# File 'lib/bio-gem/mod/jeweler.rb', line 69 def engine_dirs %w{app app/controllers app/views app/helpers config app/views/foos} end |
#engine_filename ⇒ Object
77 78 79 |
# File 'lib/bio-gem/mod/jeweler.rb', line 77 def engine_filename "#{engine_name}.rb" end |
#engine_module_name ⇒ Object
81 82 83 |
# File 'lib/bio-gem/mod/jeweler.rb', line 81 def engine_module_name project_name.split('-').map{|module_sub_name| module_sub_name.capitalize}.join end |
#engine_name ⇒ Object
73 74 75 |
# File 'lib/bio-gem/mod/jeweler.rb', line 73 def engine_name "#{project_name}-engine" end |
#engine_name_prefix ⇒ Object
85 86 87 |
# File 'lib/bio-gem/mod/jeweler.rb', line 85 def engine_name_prefix project_name.split('-').gsub(/-/,'_')<<'_' end |
#engine_namespace ⇒ Object
89 90 91 |
# File 'lib/bio-gem/mod/jeweler.rb', line 89 def engine_namespace "/#{[:biogem_engine]}" end |
#exists_dir?(dir) ⇒ Boolean
101 102 103 |
# File 'lib/bio-gem/mod/jeweler.rb', line 101 def exists_dir?(dir) Dir.exists?(File.join(target_dir,dir)) end |
#lib_dir ⇒ Object
36 37 38 |
# File 'lib/bio-gem/mod/jeweler.rb', line 36 def lib_dir 'lib' end |
#lib_filename ⇒ Object
40 41 42 |
# File 'lib/bio-gem/mod/jeweler.rb', line 40 def lib_filename "#{project_name}.rb" end |
#lib_sub_module ⇒ Object
97 98 99 |
# File 'lib/bio-gem/mod/jeweler.rb', line 97 def lib_sub_module File.join(lib_dir,"bio",sub_module.downcase) end |
#original_create_files ⇒ Object
155 |
# File 'lib/bio-gem/mod/jeweler.rb', line 155 alias original_create_files create_files |
#original_initialize ⇒ Object
19 |
# File 'lib/bio-gem/mod/jeweler.rb', line 19 alias original_initialize initialize |
#original_project_name ⇒ Object
30 |
# File 'lib/bio-gem/mod/jeweler.rb', line 30 alias original_project_name project_name |
#output_template_in_target_generic(source, destination = source, template_dir = template_dir_biogem, write_type = 'w') ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/bio-gem/mod/jeweler.rb', line 113 def output_template_in_target_generic(source, destination = source, template_dir = template_dir_biogem, write_type='w') final_destination = File.join(target_dir, destination) template_result = render_template_generic(source, template_dir) File.open(final_destination, write_type) {|file| file.write(template_result)} status = case write_type when 'w' then 'create' when 'a' then 'update' end $stdout.puts "\t#{status}\t#{destination}" end |
#output_template_in_target_generic_update(source, destination = source, template_dir = template_dir_biogem) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/bio-gem/mod/jeweler.rb', line 125 def output_template_in_target_generic_update(source, destination = source, template_dir = template_dir_biogem) final_destination = File.join(target_dir, destination) template_result = render_template_generic(source, template_dir) File.open(final_destination, 'a') {|file| file.write(template_result)} $stdout.puts "\tcreate\t#{destination}" end |
#project_name ⇒ Object
31 32 33 34 |
# File 'lib/bio-gem/mod/jeweler.rb', line 31 def project_name prj_name = original_project_name=~/^bio-/ ? original_project_name : "bio-#{original_project_name}" prj_name end |
#puts_template_message(message, length = 70, padding = 4) ⇒ Object
226 227 228 229 230 231 232 233 234 235 |
# File 'lib/bio-gem/mod/jeweler.rb', line 226 def (, length=70, padding=4) puts "*"*(length+padding*2+2) puts "*"+" "*(length+padding*2)+"*" =.join("\n") if .kind_of? Array .scan(/.{1,70}/).map do || puts "*"+" "*padding++" "*(length-.size+padding)+"*" end puts "*"+" "*(length+padding*2)+"*" puts "*"*(length+padding*2+2) end |
#render_template_generic(source, template_dir = template_dir_biogem) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/bio-gem/mod/jeweler.rb', line 105 def render_template_generic(source, template_dir = template_dir_biogem) template_contents = File.read(File.join(template_dir, source)) template = ERB.new(template_contents, nil, '<>') # squish extraneous whitespace from some of the conditionals template.result(binding).gsub(/\n\n\n+/, "\n\n") end |
#require_name ⇒ Object
49 50 51 |
# File 'lib/bio-gem/mod/jeweler.rb', line 49 def require_name project_name end |
#sub_module ⇒ Object
93 94 95 |
# File 'lib/bio-gem/mod/jeweler.rb', line 93 def sub_module project_name.split('-')[1..-1].map{|x| x.capitalize}.join end |
#target_dir ⇒ Object Also known as: github_repo_name
44 45 46 |
# File 'lib/bio-gem/mod/jeweler.rb', line 44 def target_dir project_name.gsub('bio','bioruby') end |
#template_dir_biogem ⇒ Object
134 135 136 |
# File 'lib/bio-gem/mod/jeweler.rb', line 134 def template_dir_biogem File.join(File.dirname(__FILE__),'..', 'templates') end |
#test_data_dir ⇒ Object
53 54 55 |
# File 'lib/bio-gem/mod/jeweler.rb', line 53 def test_data_dir 'test/data' end |