forked from activemerchant/active_merchant
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite generate to use Thor rather than Rubigen
Rubigen was minimally maintained, and Thor is better maintained as well as being the generator framework used by Rails since 3.0. This should also fix generating gateways when using newer versions of ActiveSupport, since Thor has no dependency on ActiveSupport at all (see activemerchant#453). Closes activemerchant#453, activemerchant#502.
- Loading branch information
Showing
15 changed files
with
98 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require "thor/group" | ||
|
||
class ActiveMerchantGenerator < Thor::Group | ||
include Thor::Actions | ||
|
||
argument :name | ||
class_option :destroy, :type => :boolean, :desc => "Destroys rather than generates the gateway" | ||
|
||
def initialize(*args) | ||
super | ||
rescue Thor::InvocationError | ||
at_exit{print self.class.help(shell)} | ||
raise | ||
end | ||
|
||
protected | ||
|
||
def template(source, dest) | ||
if options[:destroy] | ||
remove_file dest | ||
else | ||
super | ||
end | ||
end | ||
|
||
def identifier | ||
@identifier ||= class_name.gsub(%r{([A-Z])}){|m| "_#{$1.downcase}"}.sub(%r{^_}, "") | ||
end | ||
|
||
def class_name | ||
@class_name ||= name.gsub(%r{(^[a-z])|_([a-zA-Z])}){|m| ($1||$2).upcase} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,25 @@ | ||
class GatewayGenerator < RubiGen::Base | ||
LIB_DIR = "lib/active_merchant/billing/gateways/" | ||
UNIT_TEST_DIR = "test/unit/gateways/" | ||
REMOTE_TEST_DIR = "test/remote/gateways/" | ||
|
||
|
||
default_options :author => nil | ||
|
||
attr_reader :name | ||
|
||
def initialize(runtime_args, runtime_options = {}) | ||
super | ||
usage if args.length < 1 | ||
@name = args.shift | ||
extract_options | ||
end | ||
|
||
def class_name | ||
@name.classify | ||
end | ||
require "thor/group" | ||
|
||
def manifest | ||
record do |m| | ||
|
||
m.directory LIB_DIR | ||
m.directory UNIT_TEST_DIR | ||
m.directory REMOTE_TEST_DIR | ||
class GatewayGenerator < ActiveMerchantGenerator | ||
source_root File.expand_path("..", __FILE__) | ||
|
||
m.template 'gateway.rb', LIB_DIR + "#{name}.rb" | ||
m.template 'gateway_test.rb', UNIT_TEST_DIR + "#{name}_test.rb" | ||
m.template 'remote_gateway_test.rb', REMOTE_TEST_DIR + "remote_#{name}_test.rb" | ||
end | ||
def generate | ||
template "templates/gateway.rb", gateway_file | ||
template "templates/gateway_test.rb", gateway_test_file | ||
template "templates/remote_gateway_test.rb", remote_gateway_test_file | ||
end | ||
|
||
protected | ||
def banner | ||
<<-EOS | ||
Creates a ... | ||
|
||
USAGE: #{$0} #{spec.name} name" | ||
EOS | ||
end | ||
def gateway_file | ||
"lib/active_merchant/billing/gateways/#{identifier}.rb" | ||
end | ||
|
||
def gateway_test_file | ||
"test/unit/gateways/#{identifier}_test.rb" | ||
end | ||
|
||
def add_options!(opts) | ||
# opts.separator '' | ||
# opts.separator 'Options:' | ||
# For each option below, place the default | ||
# at the top of the file next to "default_options" | ||
# opts.on("-a", "--author=\"Your Name\"", String, | ||
# "Some comment about this option", | ||
# "Default: none") { |options[:author]| } | ||
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.") | ||
end | ||
|
||
def extract_options | ||
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top) | ||
# Templates can access these value via the attr_reader-generated methods, but not the | ||
# raw instance variable value. | ||
# @author = options[:author] | ||
end | ||
end | ||
def remote_gateway_test_file | ||
"lib/active_merchant/billing/gateways/remote_#{identifier}_test.rb" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,25 @@ | ||
class IntegrationGenerator < RubiGen::Base | ||
BASE_DIR = "lib/active_merchant/billing/integrations/" | ||
TEST_DIR = "test/unit/integrations/" | ||
|
||
default_options :author => nil | ||
|
||
attr_reader :name | ||
|
||
def initialize(runtime_args, runtime_options = {}) | ||
super | ||
usage if args.size < 1 | ||
@name = args.shift | ||
extract_options | ||
end | ||
|
||
def class_name | ||
name.classify | ||
end | ||
|
||
def lib_dir | ||
BASE_DIR + name | ||
end | ||
require "thor/group" | ||
|
||
class IntegrationGenerator < ActiveMerchantGenerator | ||
source_root File.expand_path("..", __FILE__) | ||
|
||
def manifest | ||
record do |m| | ||
# Ensure appropriate folder(s) exists | ||
m.directory lib_dir | ||
m.directory TEST_DIR | ||
m.directory TEST_DIR + "helpers" | ||
m.directory TEST_DIR + "notifications" | ||
|
||
m.template 'integration.rb', "#{lib_dir}.rb" | ||
m.template 'helper.rb', lib_dir + "/helper.rb" | ||
m.template 'notification.rb', lib_dir + "/notification.rb" | ||
|
||
m.template 'module_test.rb', TEST_DIR + "#{name}_module_test.rb" | ||
m.template 'helper_test.rb', TEST_DIR + "helpers/#{name}_helper_test.rb" | ||
m.template 'notification_test.rb', TEST_DIR + "notifications/#{name}_notification_test.rb" | ||
end | ||
def generate | ||
template "templates/integration.rb", "#{lib}.rb" | ||
template "templates/helper.rb", "#{lib}/helper.rb" | ||
template "templates/notification.rb", "#{lib}/notification.rb" | ||
|
||
template "templates/module_test.rb", "#{test_dir}/#{identifier}_module_test.rb" | ||
template "templates/helper_test.rb", "#{test_dir}/helpers/#{identifier}_helper_test.rb" | ||
template "templates/notification_test.rb", "#{test_dir}/notifications/#{identifier}_notification_test.rb" | ||
end | ||
|
||
protected | ||
def banner | ||
<<-EOS | ||
Creates a ... | ||
|
||
USAGE: #{$0} #{spec.name} name" | ||
EOS | ||
end | ||
def lib | ||
"lib/active_merchant/billing/integrations/#{identifier}" | ||
end | ||
|
||
def add_options!(opts) | ||
# opts.separator '' | ||
# opts.separator 'Options:' | ||
# For each option below, place the default | ||
# at the top of the file next to "default_options" | ||
# opts.on("-a", "--author=\"Your Name\"", String, | ||
# "Some comment about this option", | ||
# "Default: none") { |options[:author]| } | ||
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.") | ||
end | ||
|
||
def extract_options | ||
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top) | ||
# Templates can access these value via the attr_reader-generated methods, but not the | ||
# raw instance variable value. | ||
# @author = options[:author] | ||
end | ||
end | ||
def test_dir | ||
"test/unit/integrations" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
#!/usr/bin/env ruby | ||
APP_ROOT = File.join(File.dirname(__FILE__), '..') | ||
require "rubygems" | ||
require "thor" | ||
|
||
begin | ||
require 'rubigen' | ||
rescue LoadError | ||
require 'rubygems' | ||
require 'rubigen' | ||
require File.expand_path("../../generators/active_merchant_generator", __FILE__) | ||
|
||
Dir[File.expand_path("../..", __FILE__) + "/generators/*/*.rb"].each do |generator| | ||
require generator | ||
end | ||
|
||
class Generate < Thor | ||
register(GatewayGenerator, "gateway", "gateway NAME", "Generates a new gateway.") | ||
register(IntegrationGenerator, "integration", "integration NAME", "Generates a new integration.") | ||
end | ||
require 'rubigen/scripts/generate' | ||
|
||
ARGV.shift if ['--help', '-h'].include?(ARGV[0]) | ||
RubiGen::Base.use_component_sources! [:activemerchant, :rubygems, :test_unit] | ||
RubiGen::Scripts::Generate.new.run(ARGV) | ||
Generate.start |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.