Sha256: 6080fe825d70ae98dac65c668a7dcd4aa0a484f4e6d12222161d6cfdc28d8f80

Contents?: true

Size: 1.02 KB

Versions: 19

Compression:

Stored size: 1.02 KB

Contents

module ThreeScaleToolbox
  module Entities
    module Entity
      PRINTABLE_VARS = %w[
        id
      ].freeze

      VERBOSE_PRINTABLE_VARS = %w[
        id
      ].freeze

      public_constant :PRINTABLE_VARS
      public_constant :VERBOSE_PRINTABLE_VARS

      attr_accessor :verbose
      attr_reader :id, :attrs, :remote

      def initialize(id:, remote:, attrs: nil, verbose: false)
        @id = id.to_i
        @remote = remote
        @attrs = attrs
        @verbose = verbose
      end

      def to_s
        if @verbose
          format_vars(printable_attrs: self.class.const_get(:VERBOSE_PRINTABLE_VARS, inherit: true))
        else
          format_vars(printable_attrs: self.class.const_get(:PRINTABLE_VARS, inherit: true))
        end
      end

      private

      def format_vars(printable_attrs: nil)
        print_attrs = attrs.merge({ ":id" => @id })
        formatted_vars = printable_attrs.map do |attr|
          "#{attr} => #{attrs[attr]}"
        end
        formatted_vars.join("\n")
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
3scale_toolbox-1.0.1 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-1.0.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.20.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.19.3 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.19.2 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.19.1 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.19.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.18.3 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.18.2 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.18.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.17.1 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.17.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.16.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.15.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.14.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.13.0 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.12.4 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.12.3 lib/3scale_toolbox/entities/base_entity.rb
3scale_toolbox-0.12.2 lib/3scale_toolbox/entities/base_entity.rb