Sha256: f3d7b829c077720c2a26164f83e3384c8a5e405c1e527e39ab00810b53e55324

Contents?: true

Size: 374 Bytes

Versions: 25

Compression:

Stored size: 374 Bytes

Contents

module Marty::Enum
  def [](index)
    @LOOKUP_CACHE ||= {}

    index = index.to_s

    res = @LOOKUP_CACHE[index] ||= find_by_name(index)

    return res if res

    raise "no such #{self.name}: '#{index}'"
  end

  def to_s
    # FIXME: hacky since not all enums have name
    self.name
  end

  def clear_lookup_cache!
    @LOOKUP_CACHE.clear if @LOOKUP_CACHE
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
marty-0.5.38 app/models/marty/enum.rb
marty-0.5.36 app/models/marty/enum.rb
marty-0.5.35 app/models/marty/enum.rb
marty-0.5.34 app/models/marty/enum.rb
marty-0.5.33 app/models/marty/enum.rb
marty-0.5.32 app/models/marty/enum.rb
marty-0.5.31 app/models/marty/enum.rb
marty-0.5.30 app/models/marty/enum.rb
marty-0.5.29 app/models/marty/enum.rb
marty-0.5.28 app/models/marty/enum.rb
marty-0.5.27 app/models/marty/enum.rb
marty-0.5.26 app/models/marty/enum.rb
marty-0.5.25 app/models/marty/enum.rb
marty-0.5.24 app/models/marty/enum.rb
marty-0.5.23 app/models/marty/enum.rb
marty-0.5.21 app/models/marty/enum.rb
marty-0.5.20 app/models/marty/enum.rb
marty-0.5.19 app/models/marty/enum.rb
marty-0.5.18 app/models/marty/enum.rb
marty-0.5.17 app/models/marty/enum.rb