Sha256: 1c71947987aed3a972a521bc7c989c7d5a2748fa8bbb26c8445d44b2c33da643

Contents?: true

Size: 885 Bytes

Versions: 1

Compression:

Stored size: 885 Bytes

Contents

module Trumpet
  class Resource
    alias :old_inspect :inspect
    
    def to_h(excludes=[])
      excludes << '@credentials'
      instance_variables.inject({}) do |hash, value|
        hash[value.gsub('@', '').to_sym] = instance_variable_get(value) unless excludes.include?(value)
        hash
      end
    end
    
    def inspect
      old_inspect.gsub(/ @credentials=.*\},/, '')
    end
    
    protected
    
      def initialize(attributes)
        attributes.each do |attribute, value|
          self.class.send(:define_method, attribute) { instance_variable_get(:"@#{attribute.to_s}") }
          instance_variable_set(:"@#{attribute.to_s}", value)
        end
      end
      
    private
    
      def set_attributes(attributes)
        attributes.each do |attribute, value|
          instance_variable_set(:"@#{attribute.to_s}", value)
        end
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trumpet-trumpet-0.1.4 lib/trumpet/resource.rb