Sha256: 5c2f1c5f07b1800d81a34db94dba76b100d2b75ecbdf3dc53aed63c6a37a95a0

Contents?: true

Size: 767 Bytes

Versions: 2

Compression:

Stored size: 767 Bytes

Contents

module Trumpet
  class Resource
    
    def to_h(excludes=[])
      excludes << '@credentials'
      instance_variables.inject({}) do |hash, value|
        hash[value.gsub('@', '')] = instance_variable_get(value) unless excludes.include?(value)
        hash
      end
    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

2 entries across 2 versions & 1 rubygems

Version Path
trumpet-trumpet-0.1.2 lib/trumpet/resource.rb
trumpet-trumpet-0.1.3 lib/trumpet/resource.rb