<commit_before><%# The license inside this block applies to this file.
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
<%= compile 'templates/license.erb' -%>

<%= lines(autogen_notice :ruby) -%>

<%
  require 'google/string_utils'

  inside_indent = 8

  requires = generate_requires(object.all_user_properties)
  requires << 'inspec/resource'
  requires << 'google/hash_utils'
-%>
<%= lines(emit_requires(requires)) -%>

# A provider to manage <%= @api.name -%> resources.
class <%= object.name -%> < Inspec.resource(1)

  name 'google_<%= product_ns.downcase -%>_<%= object.name.downcase -%>'
  desc '<%= object.name -%>'
  supports platform: 'gcp-mm'

<% object.properties.each do |prop| -%>
  <%= "attr_reader :#{prop.out_name}" -%>

<% end -%>
  def base
    '<%= object.self_link_url[0].join %>'
  end

  def url
    '<%= url(object) %>'
  end

  def parse
<%
  fetch_code = object.properties.map do |prop|
    name = prop.out_name

    if primitive?(prop)
      init = "@fetched['#{prop.api_name}']"
    elsif typed_array?(prop)
      init = "#{prop.property_type}.parse(@fetched['#{prop.api_name}'])"
    else
      init = "#{prop.property_type}.new(@fetched['#{prop.api_name}'])"    
    end
    
    assignment = "@#{name} = #{init}"<commit_msg>Add singular initialize method (#591)<commit_after><%# The license inside this block applies to this file.
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
-%>
<%= compile 'templates/license.erb' -%>

<%= lines(autogen_notice :ruby) -%>

<%
  require 'google/string_utils'

  inside_indent = 8

  requires = generate_requires(object.all_user_properties)
  requires << 'inspec/resource'
  requires << 'google/hash_utils'
-%>
<%= lines(emit_requires(requires)) -%>

# A provider to manage <%= @api.name -%> resources.
class <%= object.name -%> < Inspec.resource(1)

  name 'google_<%= product_ns.downcase -%>_<%= object.name.downcase -%>'
  desc '<%= object.name -%>'
  supports platform: 'gcp-mm'

<% object.properties.each do |prop| -%>
  <%= "attr_reader :#{prop.out_name}" -%>

<% end -%>
  def base
    '<%= object.self_link_url[0].join %>'
  end

  def url
    '<%= url(object) %>'
  end

<% if object.self_link_query.nil? -%>
  def initialize(params)
    @fetched = fetch_resource(params)
    parse unless @fetched.nil?
  end
<% else # object.self_link_query.nil? -%>
   # TODO(slevenick) for other products
   def initialize(params)
     raise 'Not implemented'
   end
<% end # object.self_link_query.nil? -%>

  def fetch_resource(params)
    get_request = inspec.backend.fetch(base, url, params)
  end

  def parse
<%
  fetch_code = object.properties.map do |prop|
    name = prop.out_name

    if primitive?(prop)
      init = "@fetched['#{prop.api_name}']"
    elsif typed_array?(prop)
      init = "#{prop.property_type}.parse(@fetched['#{prop.api_name}'])"
    else
      init = "#{prop.property_type}.new(@fetched['#{prop.api_name}'])"    
    end
    
    assignment = "@#{name} = #{init}"
{'fraction_non_alphanumeric': 0.14955134596211367, 'fraction_numerical': 0.006231306081754736, 'mean_word_length': 3.749112426035503, 'pattern_counts': {'":': 0, '<': 48, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5816692', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1307, 'n_words': 358}