class SimpleEnumeration::CollectionMethodsDefiner
Attributes
collection[R]
enum_class[R]
Public Class Methods
call(*params, **options, &block)
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 12 def self.call(*params, **options, &block) new(*params, **options).call(&block) end
new(enum_class:, collection:)
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 7 def initialize(enum_class:, collection:) @enum_class = enum_class @collection = collection end
Public Instance Methods
call()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 16 def call set_collection define_singleton_collection define_singleton_collection_values_method define_singleton_collection_value_predicate_method define_singleton_collection_for_select_method define_singleton_collection_humanized_method define_instance_collection_value_predicate_method end
Private Instance Methods
define_instance_collection_value_predicate_method()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 72 def define_instance_collection_value_predicate_method enum_class.define_method collection.value_predicate_method_name do return false unless type collection_name = Collection.collection_name_from_value_predicate_method_name(__method__) self.class.get_collection(collection_name).types.values.map(&:converted_value).include?(type.converted_value) end end
define_singleton_collection()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 32 def define_singleton_collection enum_class.define_singleton_method collection.method_name do collection_name = Collection.collection_name_from_method_name(__method__) get_collection(collection_name) end end
define_singleton_collection_for_select_method()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 56 def define_singleton_collection_for_select_method enum_class.define_singleton_method collection.for_select_method_name do collection_name = Collection.collection_name_from_for_select_method_name(__method__) get_collection(collection_name).types.values.map(&:for_select) end end
define_singleton_collection_humanized_method()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 64 def define_singleton_collection_humanized_method enum_class.define_singleton_method collection.humanized_method_name do collection_name = Collection.collection_name_from_humanized_method_name(__method__) get_collection(collection_name).types.values.map(&:humanized) end end
define_singleton_collection_value_predicate_method()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 48 def define_singleton_collection_value_predicate_method enum_class.define_singleton_method collection.value_predicate_method_name do |converted_value| collection_name = Collection.collection_name_from_value_predicate_method_name(__method__) get_collection(collection_name).types.values.map(&:converted_value).include?(converted_value) end end
define_singleton_collection_values_method()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 40 def define_singleton_collection_values_method enum_class.define_singleton_method collection.value_method_name do collection_name = Collection.collection_name_from_value_method_name(__method__) get_collection(collection_name).types.values.map(&:converted_value) end end
set_collection()
click to toggle source
# File lib/simple_enumeration/collection_methods_definer.rb, line 28 def set_collection enum_class.set_collection(collection.name, collection) end