Sha256: 8fe5a66da681574bb680206bd7593fb0fc8bb972301379b9e4aef008085a00af
Contents?: true
Size: 1.27 KB
Versions: 79
Compression:
Stored size: 1.27 KB
Contents
# frozen_string_literal: true require 'active_support/hash_with_indifferent_access' require 'active_support/core_ext/string/inflections' require_relative 'integer_list' require_relative 'string_list' require_relative 'symbol_list' module EacRubyUtils module Listable class Lists attr_reader :source def initialize(source) @source = source end %w[integer string symbol].each do |list_type| define_method "add_#{list_type}" do |item, *labels| add(::EacRubyUtils::Listable.const_get("#{list_type}_list".camelize), item, labels) end end def method_missing(name, *args, &block) list = find_list_by_method(name) list || super end def respond_to_missing?(name, include_all = false) find_list_by_method(name) || super end def acts_as_listable_items @acts_as_listable_items ||= ActiveSupport::HashWithIndifferentAccess.new end private def add(list_class, item, labels) acts_as_listable_items[item] = list_class.new(self, item, labels) end def find_list_by_method(method) acts_as_listable_items.each do |item, list| return list if method.to_sym == item.to_sym end nil end end end end
Version data entries
79 entries across 79 versions & 2 rubygems