Sha256: f168391f436d2132baf7c26553d37b7f499ab862b71dcae3aaa7cbce7a2e9f35

Contents?: true

Size: 976 Bytes

Versions: 11

Compression:

Stored size: 976 Bytes

Contents

module Taza
  class Entity
    #Creates a entity, pass in a hash to be methodized and the fixture to look up other fixtures (not entirely happy with this abstraction)
    def initialize(hash,fixture)
      @hash = hash
      @fixture = fixture
      define_methods_for_hash_keys
    end
    
    #This method converts hash keys into methods onto the entity
    def define_methods_for_hash_keys
      @hash.keys.each do |key|
        create_method(key) do
          get_value_for_entry(key)
        end
      end
    end

    #This method will lookup another fixture if a pluralized fixture exists otherwise return the value in the hash
    def get_value_for_entry(key) # :nodoc:
      if @fixture.pluralized_fixture_exists?(key)
        @fixture.get_fixture_entity(key.pluralize_to_sym,@hash[key])
      else
        @hash[key]
      end
    end

    private
    def create_method(name, &block) # :nodoc:
      self.class.send(:define_method, name, &block)
    end

  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
bret-watircraft-0.4.0 lib/taza/entity.rb
bret-watircraft-0.4.1 lib/taza/entity.rb
bret-watircraft-0.4.2 lib/taza/entity.rb
bret-watircraft-0.4.3 lib/taza/entity.rb
bret-watircraft-0.4.4 lib/taza/entity.rb
bret-watircraft-0.4.5 lib/taza/entity.rb
bret-watircraft-0.5.0 lib/taza/entity.rb
scudco-taza-0.8.1 lib/taza/entity.rb
scudco-taza-0.8.3 lib/taza/entity.rb
taza-0.8.3 lib/taza/entity.rb
taza-0.8.2 lib/taza/entity.rb