Drop active support as a hard runtime depdendency. Still required for code generation however. #364
This commit is contained in:
parent
acf2b0ec61
commit
e67964189e
1
Gemfile
1
Gemfile
|
@ -21,6 +21,7 @@ group :development do
|
||||||
gem 'rmail', '~> 1.1'
|
gem 'rmail', '~> 1.1'
|
||||||
gem 'sinatra', '~> 1.4'
|
gem 'sinatra', '~> 1.4'
|
||||||
gem 'redis', '~> 3.2'
|
gem 'redis', '~> 3.2'
|
||||||
|
gem 'activesupport', '>= 3.2'
|
||||||
end
|
end
|
||||||
|
|
||||||
platforms :jruby do
|
platforms :jruby do
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
# TODO - Repeated params
|
|
||||||
|
|
||||||
require 'thor'
|
require 'thor'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
require 'google/apis/discovery_v1'
|
require 'google/apis/discovery_v1'
|
||||||
require 'google/apis/generator'
|
|
||||||
require 'logger'
|
require 'logger'
|
||||||
|
|
||||||
module Google
|
module Google
|
||||||
class ApiGenerator < Thor
|
class ApiGenerator < Thor
|
||||||
|
|
||||||
|
def self.exit_on_failure?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
|
|
||||||
Google::Apis::ClientOptions.default.application_name = "generate-api"
|
Google::Apis::ClientOptions.default.application_name = "generate-api"
|
||||||
|
@ -23,6 +25,9 @@ module Google
|
||||||
names_out: :string
|
names_out: :string
|
||||||
method_option :preferred_only, default: true
|
method_option :preferred_only, default: true
|
||||||
def gen(dir)
|
def gen(dir)
|
||||||
|
ensure_active_support
|
||||||
|
require 'google/apis/generator'
|
||||||
|
|
||||||
self.destination_root = dir
|
self.destination_root = dir
|
||||||
Google::Apis.logger.level = Logger::DEBUG if options[:verbose]
|
Google::Apis.logger.level = Logger::DEBUG if options[:verbose]
|
||||||
generate_from_url(options[:url]) if options[:url]
|
generate_from_url(options[:url]) if options[:url]
|
||||||
|
@ -86,6 +91,16 @@ module Google
|
||||||
def generator
|
def generator
|
||||||
@generator ||= Google::Apis::Generator.new(api_names: options[:names])
|
@generator ||= Google::Apis::Generator.new(api_names: options[:names])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_active_support
|
||||||
|
begin
|
||||||
|
require 'active_support/inflector'
|
||||||
|
rescue LoadError => e
|
||||||
|
error 'ActiveSupport is required, please run:'
|
||||||
|
error 'gem install activesupport'
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
require 'active_support/inflector'
|
|
||||||
require 'addressable/uri'
|
require 'addressable/uri'
|
||||||
require 'addressable/template'
|
require 'addressable/template'
|
||||||
require 'google/apis/core/http_command'
|
require 'google/apis/core/http_command'
|
||||||
|
@ -127,7 +126,9 @@ module Google
|
||||||
# Updated header value
|
# Updated header value
|
||||||
def normalize_fields_param(fields)
|
def normalize_fields_param(fields)
|
||||||
# TODO: Generate map of parameter names during code gen. Small possibility that camelization fails
|
# TODO: Generate map of parameter names during code gen. Small possibility that camelization fails
|
||||||
fields.gsub(/:/, '').gsub(/\w+/) { |str| ActiveSupport::Inflector.camelize(str, false) }
|
fields.gsub(/:/, '').gsub(/\w+/) do |str|
|
||||||
|
str.gsub(/(?:^|_)([a-z])/){ Regexp.last_match.begin(0) == 0 ? $1 : $1.upcase }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -103,7 +103,7 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
||||||
context('with a field parameter') do
|
context('with a field parameter') do
|
||||||
let(:command) do
|
let(:command) do
|
||||||
command = Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
command = Google::Apis::Core::ApiCommand.new(:get, 'https://www.googleapis.com/zoo/animals')
|
||||||
command.query['fields'] = ':items(:id, :long_name)'
|
command.query['fields'] = ':items(:id, :long_name, :a_really_long_name), shouldBeLeftAlone '
|
||||||
command
|
command
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
||||||
it 'should normalize fields params' do
|
it 'should normalize fields params' do
|
||||||
command.execute(client)
|
command.execute(client)
|
||||||
expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
|
expect(a_request(:get, 'https://www.googleapis.com/zoo/animals')
|
||||||
.with(query: { 'fields' => 'items(id, longName)' })) .to have_been_made
|
.with(query: { 'fields' => 'items(id, longName, aReallyLongName), shouldBeLeftAlone ' })) .to have_been_made
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue