Skip to content

Commit

Permalink
Add override for exclude_reader in InSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick committed Mar 13, 2019
1 parent b78c1c0 commit 9088ce5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion overrides/inspec/property_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class PropertyOverride < Overrides::PropertyOverride
def self.attributes
[
:name_from_self_link, # Set to convert self link to name
:exclude_plural
:exclude_plural,
:exclude_reader # Set to exclude the attribute reader within generated resources
]
end

Expand All @@ -32,6 +33,7 @@ def self.attributes
def self.validate
check :name_from_self_link, type: :boolean, default: false
check :exclude_plural, type: :boolean, default: false
check :exclude_reader, type: :boolean, default: false
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions products/bigquery/inspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
properties:
description: !ruby/object:Overrides::Inspec::PropertyOverride
exclude_plural: true
exclude_reader: true
access: !ruby/object:Overrides::Inspec::PropertyOverride
exclude_plural: true
defaultTableExpirationMs: !ruby/object:Overrides::Inspec::PropertyOverride
Expand All @@ -29,6 +30,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides
exclude_plural: true
name: !ruby/object:Overrides::Inspec::PropertyOverride
exclude_plural: true
exclude_reader: true
lastModifiedTime: !ruby/object:Overrides::Inspec::PropertyOverride
exclude_plural: true
additional_functions: |
Expand All @@ -38,7 +40,5 @@ overrides: !ruby/object:Overrides::ResourceOverrides
Table: !ruby/object:Overrides::Inspec::ResourceOverride
properties:
name: !ruby/object:Overrides::Inspec::PropertyOverride
exclude_plural: true
description: !ruby/object:Overrides::Inspec::PropertyOverride
exclude_plural: true
4 changes: 2 additions & 2 deletions templates/inspec/plural_resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ name = "google_#{product_ns.downcase}_#{object.name.underscore}"
attr_reader :table

filter_table_config = FilterTable.create
<% object.all_user_properties.reject {|prop| prop.exclude_plural }.each do |prop| -%>
<% object.all_user_properties.reject(&:exclude_plural).reject(&:exclude_reader).each do |prop| -%>

<%= "filter_table_config.add(:#{prop.out_name.pluralize}, field: :#{prop.out_name})" -%>
<% end # object.all_user_properties.each do -%>
Expand Down Expand Up @@ -74,7 +74,7 @@ link_query = object.self_link_query || object.collection_url_response

def transformers
{
<% object.all_user_properties.reject(&:exclude_plural).each do |prop| -%>
<% object.all_user_properties.reject(&:exclude_plural).reject(&:exclude_reader).each do |prop| -%>
'<%= prop.api_name -%>' => ->(obj) { <%= "return :#{prop.out_name}, #{parse_code(prop, 'obj')}" -%> },
<% end # object.all_user_properties.each -%>
}
Expand Down
4 changes: 2 additions & 2 deletions templates/inspec/singular_resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class <%= object.name -%> < GcpResourceBase
desc '<%= object.name -%>'
supports platform: 'gcp'

<% object.all_user_properties.each do |prop| -%>
<% object.all_user_properties.reject(&:exclude_reader).each do |prop| -%>
<%= "attr_reader :#{prop.out_name}" -%>

<% end -%>
Expand Down Expand Up @@ -67,7 +67,7 @@ class <%= object.name -%> < GcpResourceBase

def parse
<%
parse_code = object.all_user_properties.map do |prop|
parse_code = object.all_user_properties.reject(&:exclude_reader).map do |prop|
assignment = "@#{prop.out_name} = #{parse_code(prop, '@fetched')}"
end
-%>
Expand Down

0 comments on commit 9088ce5

Please sign in to comment.