class Hashie::Trash

in Ruby.
such as a Java api, where the keys are named differently from how we would
Trashes are useful when you need to read data from another application,
hash.
A Trash is a ‘translated’ Dash where the keys can be remapped from a source

def self.property(property_name, options = {})

* :from - Specify the original key name that will be write only.
returned before a value is set on the property in a new Dash.
* :default - Specify a default value for this property, to be

Defines a property on the Trash. Options are as follows:
def self.property(property_name, options = {})
  super
  if options[:from]
    translations << options[:from].to_sym
    class_eval <<-RUBY
      def #{options[:from]}=(val)
        self[:#{property_name}] = val
      end
    RUBY
  end
end

def self.translations

def self.translations
  @translations ||= []
end

def []=(property, value)

on pre-existing properties.
Set a value on the Dash in a Hash-like way. Only works
def []=(property, value)
  if self.class.translations.include? property.to_sym
    send("#{property}=", value)
  elsif property_exists? property
    super
  end
end

def property_exists?(property)


Raises an NoMethodError if the property doesn't exist
def property_exists?(property)
  unless self.class.property?(property.to_sym)
    raise NoMethodError, "The property '#{property}' is not defined for this Trash."
  end
  true
end