Sha256: e4ec74c5f30a267e08b62f37a5dccb6bae2efe0c212eb961d99015914fbb8743
Contents?: true
Size: 1.12 KB
Versions: 13
Compression:
Stored size: 1.12 KB
Contents
module Avo module Fields class FieldManager class << self def build instance = new instance.init_fields instance end end attr_reader :fields alias_method :all, :fields def initialize @fields = [] end # This method will find all fields available in the Avo::Fields namespace and add them to the fields class_variable array # so later we can instantiate them on our resources. # # If the field has their `def_method` set up it will follow that convention, if not it will snake_case the name: # # Avo::Fields::TextField -> text # Avo::Fields::DateTimeField -> date_time def init_fields Avo::Fields::BaseField.descendants.each do |class_name| next if class_name.to_s == "BaseField" if class_name.to_s.end_with? "Field" load_field class_name.get_field_name, class_name end end end def load_field(method_name, klass) fields.push( name: method_name, class: klass ) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems