Sha256: ac8a93922e16db90f2cb214bab058fe8878458bb2b984ce93e271b45c18cec12
Contents?: true
Size: 1.43 KB
Versions: 17
Compression:
Stored size: 1.43 KB
Contents
# frozen_string_literal: true module Tramway module Forms # This is `properties`. The main feature of Tramway Form module Properties # A collection of methods that would be using in users forms module ClassMethods def property(attribute) @properties << attribute delegate attribute, to: :object end def properties(*attributes) attributes.any? ? __set_properties(attributes) : __properties end def __set_properties(attributes) attributes.each do |attribute| property(attribute) end end def __properties (__ancestor_properties + @properties).uniq end # :reek:ManualDispatch { enabled: false } def __ancestor_properties(klass = superclass) superklass = klass.superclass return [] unless superklass.respond_to?(:properties) klass.properties + __ancestor_properties(superklass) end # :reek:UtilityFunction { enabled: false } def __initialize_properties(subclass) subclass.instance_variable_set(:@properties, []) end end def self.included(base) base.extend ClassMethods end def __apply_properties(params) self.class.properties.each do |attribute| public_send("#{attribute}=", params[attribute]) if params.key?(attribute) end end end end end
Version data entries
17 entries across 17 versions & 1 rubygems