Class: Jeweler::Generator

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(options = {}) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
15
16
17
18
# File 'lib/bio-gem/mod/jeweler.rb', line 10

def initialize(options = {})
  original_initialize(options)
  development_dependencies << ["bio", ">= 1.4.1"]
  if options[: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_dirObject



51
52
53
# File 'lib/bio-gem/mod/jeweler.rb', line 51

def bin_dir
  'bin'
end

#bin_nameObject



55
56
57
# File 'lib/bio-gem/mod/jeweler.rb', line 55

def bin_name
  "bio#{original_project_name}"
end

#create_and_push_repoObject



134
135
136
137
138
139
140
141
142
# File 'lib/bio-gem/mod/jeweler.rb', line 134

def create_and_push_repo
  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
  # TODO do a HEAD request to see when it's ready?
  @repo.push('origin')
end

#create_db_structureObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/bio-gem/mod/jeweler.rb', line 84

def create_db_structure
  migrate_dir = File.join(db_dir, "migrate")
  mkdir_in_target(db_dir)
  mkdir_in_target(migrate_dir)
  mkdir_in_target("conf")
  output_template_in_target_generic 'database', File.join("conf", "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
end

#create_filesObject

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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/bio-gem/mod/jeweler.rb', line 99

def create_files
  if options[: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 options[:biogem_test_data]
      mkdir_in_target("test") unless File.exists? "#{target_dir}/test"
      mkdir_in_target test_data_dir  
    end
    create_db_structure if options[:biogem_db]
    if options[: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)
  end #not_bio_gem_meta
end

#db_dirObject



47
48
49
# File 'lib/bio-gem/mod/jeweler.rb', line 47

def db_dir
  'db'
end

#lib_dirObject



26
27
28
# File 'lib/bio-gem/mod/jeweler.rb', line 26

def lib_dir
  'lib'
end

#lib_filenameObject



30
31
32
# File 'lib/bio-gem/mod/jeweler.rb', line 30

def lib_filename
  "#{project_name}.rb"
end

#original_create_filesObject



95
# File 'lib/bio-gem/mod/jeweler.rb', line 95

alias original_create_files create_files

#original_initializeObject



9
# File 'lib/bio-gem/mod/jeweler.rb', line 9

alias original_initialize initialize

#original_project_nameObject



20
# File 'lib/bio-gem/mod/jeweler.rb', line 20

alias original_project_name project_name

#output_template_in_target_generic(source, destination = source, template_dir = template_dir_biogem, write_type = 'w') ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bio-gem/mod/jeweler.rb', line 67

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

#project_nameObject



21
22
23
24
# File 'lib/bio-gem/mod/jeweler.rb', line 21

def project_name
  prj_name = original_project_name=~/^bio-/ ? original_project_name : "bio-#{original_project_name}" 
  prj_name
end

#render_template_generic(source, template_dir = template_dir_biogem) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/bio-gem/mod/jeweler.rb', line 59

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_nameObject



39
40
41
# File 'lib/bio-gem/mod/jeweler.rb', line 39

def require_name
  project_name
end

#target_dirObject Also known as: github_repo_name



34
35
36
# File 'lib/bio-gem/mod/jeweler.rb', line 34

def target_dir
  project_name.gsub('bio','bioruby')
end

#template_dir_biogemObject



79
80
81
# File 'lib/bio-gem/mod/jeweler.rb', line 79

def template_dir_biogem
  File.join(File.dirname(__FILE__),'..', 'templates')
end

#test_data_dirObject



43
44
45
# File 'lib/bio-gem/mod/jeweler.rb', line 43

def test_data_dir
  'test/data'
end