Class: Ruboty::Gen::Gem

Inherits:
Object
  • Object
show all
Defined in:
lib/ruboty/gen/gem.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, ruboty_plugin_name, actions, thor) ⇒ Gem

Returns a new instance of Gem.



6
7
8
9
10
11
# File 'lib/ruboty/gen/gem.rb', line 6

def initialize(options, ruboty_plugin_name, actions, thor)
  @options = options
  @ruboty_plugin_name = ruboty_plugin_name.chomp("/")
  @actions = actions
  @thor = thor
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



4
5
6
# File 'lib/ruboty/gen/gem.rb', line 4

def actions
  @actions
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/ruboty/gen/gem.rb', line 4

def options
  @options
end

#ruboty_plugin_nameObject (readonly)

Returns the value of attribute ruboty_plugin_name.



4
5
6
# File 'lib/ruboty/gen/gem.rb', line 4

def ruboty_plugin_name
  @ruboty_plugin_name
end

#thorObject (readonly)

Returns the value of attribute thor.



4
5
6
# File 'lib/ruboty/gen/gem.rb', line 4

def thor
  @thor
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ruboty/gen/gem.rb', line 13

def run
  ### copy from bundler :P
  name = "ruboty-#{ruboty_plugin_name}" # remove trailing slash if present
  ruboty_plugin_constant_name = ruboty_plugin_name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
  underscored_name = name.tr('-', '_')
  namespaced_path = name.tr('-', '/')
  target = File.join(Dir.pwd, name)
  constant_name = name.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join
  constant_name = constant_name.split('-').map{|q| q[0..0].upcase + q[1..-1] }.join('::') if constant_name =~ /-/
  constant_array = constant_name.split('::')
  git_user_name = `git config user.name`.chomp
  git_user_email = `git config user.email`.chomp
  constant_actions = actions.map { |e|camelize(e) }

  opts = {
    :name               => name,
    :ruboty_plugin_name => ruboty_plugin_name,
    :ruboty_plugin_constant_name => ruboty_plugin_constant_name,
    :underscored_name   => underscored_name,
    :namespaced_path    => namespaced_path,
    :makefile_path      => "#{underscored_name}/#{underscored_name}",
    :constant_name      => constant_name,
    :constant_array     => constant_array,
    :author             => git_user_name.empty? ? "TODO: Write your name" : git_user_name,
    :email              => git_user_email.empty? ? "TODO: Write your email address" : git_user_email,
    :test               => options[:test],
    :ext                => options[:ext],
    :actions            => actions,
    :constant_actions   => constant_actions
  }

  thor.template(File.join('ruboty/handlers/newgem.rb.tt'),       File.join(target, "lib/ruboty/handlers/#{ruboty_plugin_name}.rb"),            opts)
  action_template = @options['rescue'] ? 'newgem_rescue.rb.tt' : 'newgem.rb.tt'
  actions.each do |action|
    opts[:constant_action] = camelize(action)
    opts[:action] = action
    thor.template(File.join("ruboty/newgem/actions/#{action_template}"), File.join(target, "lib/ruboty/#{ruboty_plugin_name}/actions/#{action}.rb"), opts)
  end
end