<commit_before>require 'fog/model'

module Fog
  module Vcloud
    module Terremark
      module Ecloud
        class InternetService < Fog::Vcloud::Model

          identity :href

          attribute :name
          attribute :id
          attribute :type
          attribute :protocol
          attribute :port
          attribute :enabled
          attribute :description
          attribute :public_ip
          attribute :timeout
          attribute :url_send_string
          attribute :http_header

          attr_accessor :new

          def delete
            requires :href

            connection.delete_internet_service( self.href )
            collection.reload
          end

          def save
            if new?
              result = connection.add_internet_service( collection.href, _compose_service_data )
              self.href = result.body.href
              self.reload
              @new = false
            else
              connection.configure_internet_service( self.href, _compose_service_data, _compose_ip_data )
            end
          end

          def new?
            @new ||= false
          end

          private

          def _compose_service_data
            service_data = {}
            self.class.attributes.select{ |attribute| !attribute.nil? }.each { |attribute| service_data[attribute] = send(attribute).to_s }
            service_data
          end

          def _compose_ip_data
            if public_ip.nil?
              {}
            else
              { :id => self.public_ip.id, :href => self.public_ip.href.to_s, :name => self.public_ip.name }
            end
          end

        end
      end
    end
  end
end


<commit_msg>use new_record? instead of new?<commit_after>require 'fog/model'

module Fog
  module Vcloud
    module Terremark
      module Ecloud
        class InternetService < Fog::Vcloud::Model

          identity :href

          attribute :name
          attribute :id
          attribute :type
          attribute :protocol
          attribute :port
          attribute :enabled
          attribute :description
          attribute :public_ip
          attribute :timeout
          attribute :url_send_string
          attribute :http_header

          attr_accessor :new

          def delete
            requires :href

            connection.delete_internet_service( self.href )
            collection.reload
          end

          def save
            if new_record?
              result = connection.add_internet_service( collection.href, _compose_service_data )
              self.href = result.body.href
              self.reload
            else
              connection.configure_internet_service( self.href, _compose_service_data, _compose_ip_data )
            end
          end

          private

          def _compose_service_data
            service_data = {}
            self.class.attributes.select{ |attribute| !attribute.nil? }.each { |attribute| service_data[attribute] = send(attribute).to_s }
            service_data
          end

          def _compose_ip_data
            if public_ip.nil?
              {}
            else
              { :id => self.public_ip.id, :href => self.public_ip.href.to_s, :name => self.public_ip.name }
            end
          end

        end
      end
    end
  end
end



{'fraction_non_alphanumeric': 0.0605604097619765, 'fraction_numerical': 0.0, 'mean_word_length': 1.4757643549589858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1215247', 'n_tokens_mistral': 857, 'n_tokens_neox': 832, 'n_words': 203}