Sha256: 1cf811871048c7e0ed950744c4fd3c779f4cbbea6fc4f6c6516fad14862e794e
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
require 'json' module WAEasyAPI # Entity class is the base class for all WAEasyAPI objects # This saves data in a hash internally, and makes it available # via direct methods class Entity attr_reader :attributes def initialize(attributes) @attributes = attributes end # This method fakes attr_reader, but uses # the @attributes hash as the source, instead of # instance variables def method_missing(name) if @attributes.key? name.to_s @attributes[name.to_s] else super end end def respond_to_missing?(method_name, include_private = false) @attributes.key?(method_name.to_s) || super end # Public: Convert the Entity object to JSON # Returns the JSON representation of the Entity (as a string) def to_json(*args) @attributes.to_json(*args) end # Mutates the entity in accordance with # the block passed to this construct # # Used to implement bang methods, by calling # the non-bang method in the passed block def with_a_bang mutated_entity = yield @attributes = mutated_entity.attributes mutated_entity end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
waeasyapi-1.0.0 | lib/waeasyapi/entity.rb |