From 0ccecf3aaaaf9010dbe04123702b5d17564d6e33 Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 12 Sep 2018 10:53:56 -0700 Subject: [PATCH 1/3] Adding ability to override classes This will let us override types. For example, TF could have a property act as a String, while everything else treats it as a ResourceRef... --- api/type.rb | 24 ++++++++++++++++++++++-- provider/property_override.rb | 3 +++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/api/type.rb b/api/type.rb index 6f7a096a11a7..5edaf8417f79 100644 --- a/api/type.rb +++ b/api/type.rb @@ -37,6 +37,10 @@ module Fields # "ForceSendFields" concepts in the autogenerated API clients. attr_reader :send_empty_value attr_reader :min_version + + # Can only be overriden - we should never set this ourselves. + attr_reader :new_type + end include Fields @@ -128,6 +132,22 @@ def exclude_if_not_in_version(version) @exclude ||= version < min_version end + # Overriding is_a? to enable class overrides. + # Ruby does not let you natively change types, so this is the next best + # thing. + def is_a?(clazz) + return Module.const_get(@new_type).new.is_a?(clazz) if @new_type + return super(clazz) + end + + # Overriding class to enable class overrides. + # Ruby does not let you natively change types, so this is the next best + # thing. + def class + return Module.const_get(@new_type) if @new_type + super + end + private # A constant value to be provided as field @@ -158,8 +178,8 @@ class Double < Primitive # Represents a string class String < Primitive - def initialize(name) - @name = name + def initialize(name = nil) + @name ||= name end PROJECT = Api::Type::String.new('project') diff --git a/provider/property_override.rb b/provider/property_override.rb index ebb5949dfd7d..1af9a641ae8a 100644 --- a/provider/property_override.rb +++ b/provider/property_override.rb @@ -18,6 +18,9 @@ module Provider # Override a resource property (Api::Type) in api.yaml # TODO(rosbo): Shared common logic with ResourceOverride via a base class. class PropertyOverride < Api::Object + + attr_reader :new_type + include Api::Type::Fields # To allow overrides for type-specific fields, include those type's # fields with an 'include' directive here. From 4b89e547e09f7bc8167a9652ea0cc0088562480b Mon Sep 17 00:00:00 2001 From: Alex Stephen Date: Wed, 12 Sep 2018 10:58:16 -0700 Subject: [PATCH 2/3] rubocop --- api/type.rb | 5 +++-- provider/property_override.rb | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/type.rb b/api/type.rb index 5edaf8417f79..ca098427e217 100644 --- a/api/type.rb +++ b/api/type.rb @@ -16,6 +16,7 @@ module Api # Represents a property type + # rubocop:disable Metrics/ClassLength class Type < Api::Object::Named # The list of properties (attr_reader) that can be overridden in # .yaml. @@ -40,7 +41,6 @@ module Fields # Can only be overriden - we should never set this ourselves. attr_reader :new_type - end include Fields @@ -137,7 +137,7 @@ def exclude_if_not_in_version(version) # thing. def is_a?(clazz) return Module.const_get(@new_type).new.is_a?(clazz) if @new_type - return super(clazz) + super(clazz) end # Overriding class to enable class overrides. @@ -538,4 +538,5 @@ def property_ns_prefix ] end end + # rubocop:enable Metrics/ClassLength end diff --git a/provider/property_override.rb b/provider/property_override.rb index 1af9a641ae8a..6b222d750b4f 100644 --- a/provider/property_override.rb +++ b/provider/property_override.rb @@ -18,7 +18,6 @@ module Provider # Override a resource property (Api::Type) in api.yaml # TODO(rosbo): Shared common logic with ResourceOverride via a base class. class PropertyOverride < Api::Object - attr_reader :new_type include Api::Type::Fields From 2312b4d3a327dda73932be7950936f0c20712afd Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 12 Sep 2018 19:50:31 +0000 Subject: [PATCH 3/3] Update tracked submodules -> HEAD on Wed Sep 12 19:50:31 UTC 2018 Tracked submodules are build/puppet/_bundle build/puppet/auth build/puppet/bigquery build/puppet/compute build/puppet/sql build/puppet/storage build/puppet/spanner build/puppet/container build/puppet/dns build/puppet/pubsub build/puppet/resourcemanager build/chef/_bundle build/chef/auth build/chef/compute build/chef/sql build/chef/storage build/chef/spanner build/chef/container build/chef/dns build/chef/iam build/terraform build/ansible. --- build/ansible | 2 +- build/puppet/compute | 2 +- build/terraform | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/ansible b/build/ansible index 152fe2f7ef03..234cebdc7280 160000 --- a/build/ansible +++ b/build/ansible @@ -1 +1 @@ -Subproject commit 152fe2f7ef03501cd440f6043aaf75754661dcfe +Subproject commit 234cebdc728097999bd2920d1741352c16ed38c8 diff --git a/build/puppet/compute b/build/puppet/compute index f85ca51781a0..7ebaf138b2e8 160000 --- a/build/puppet/compute +++ b/build/puppet/compute @@ -1 +1 @@ -Subproject commit f85ca51781a0cd97ac365c4419fbcb14b29f0c6f +Subproject commit 7ebaf138b2e8e99237de48b148a8e6ead9de16f3 diff --git a/build/terraform b/build/terraform index f05d62c89e2a..f1bd5029afd9 160000 --- a/build/terraform +++ b/build/terraform @@ -1 +1 @@ -Subproject commit f05d62c89e2abf3cc2fd75a52715b88c62db4ab0 +Subproject commit f1bd5029afd9ed6032f194f1e2fe5f5ad0c4a693