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 'sinatra', '~> 1.4'
|
||||
gem 'redis', '~> 3.2'
|
||||
gem 'activesupport', '>= 3.2'
|
||||
end
|
||||
|
||||
platforms :jruby do
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# TODO - Repeated params
|
||||
|
||||
require 'thor'
|
||||
require 'open-uri'
|
||||
require 'google/apis/discovery_v1'
|
||||
require 'google/apis/generator'
|
||||
require 'logger'
|
||||
|
||||
module Google
|
||||
class ApiGenerator < Thor
|
||||
|
||||
def self.exit_on_failure?
|
||||
true
|
||||
end
|
||||
|
||||
include Thor::Actions
|
||||
|
||||
Google::Apis::ClientOptions.default.application_name = "generate-api"
|
||||
|
@ -23,6 +25,9 @@ module Google
|
|||
names_out: :string
|
||||
method_option :preferred_only, default: true
|
||||
def gen(dir)
|
||||
ensure_active_support
|
||||
require 'google/apis/generator'
|
||||
|
||||
self.destination_root = dir
|
||||
Google::Apis.logger.level = Logger::DEBUG if options[:verbose]
|
||||
generate_from_url(options[:url]) if options[:url]
|
||||
|
@ -86,6 +91,16 @@ module Google
|
|||
def generator
|
||||
@generator ||= Google::Apis::Generator.new(api_names: options[:names])
|
||||
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
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
require 'active_support/inflector'
|
||||
require 'addressable/uri'
|
||||
require 'addressable/template'
|
||||
require 'google/apis/core/http_command'
|
||||
|
@ -127,7 +126,9 @@ module Google
|
|||
# Updated header value
|
||||
def normalize_fields_param(fields)
|
||||
# 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
|
||||
|
|
|
@ -103,7 +103,7 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
|||
context('with a field parameter') do
|
||||
let(:command) do
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -115,7 +115,7 @@ RSpec.describe Google::Apis::Core::HttpCommand do
|
|||
it 'should normalize fields params' do
|
||||
command.execute(client)
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue