class Rodauth::Feature
def self.define(name, constant=nil, &block)
def self.define(name, constant=nil, &block) feature = new feature.dependencies = [] feature.routes = [] feature.feature_name = name configuration = feature.configuration = FeatureConfiguration.new feature.module_eval(&block) configuration.def_configuration_methods(feature) if constant Rodauth.const_set(constant, feature) Rodauth::FeatureConfiguration.const_set(constant, configuration) end FEATURES[name] = feature end
def additional_form_tags(name=feature_name)
def additional_form_tags(name=feature_name) auth_value_method(:"#{name}_additional_form_tags", nil) end
def auth_cached_method(meth, iv=:"@#{meth}")
def auth_cached_method(meth, iv=:"@#{meth}") umeth = :"_#{meth}" define_method(meth) do if instance_variable_defined?(iv) instance_variable_get(iv) else instance_variable_set(iv, send(umeth)) end end auth_private_methods(meth) end
def auth_value_method(meth, value)
def auth_value_method(meth, value) define_method(meth){value} auth_value_methods(meth) end
def configuration_module_eval(&block)
def configuration_module_eval(&block) configuration.module_eval(&block) end
def depends(*deps)
def depends(*deps) dependencies.concat(deps) end
def loaded_templates(v)
def loaded_templates(v) define_method(:loaded_templates) do super().concat(v) end end
def redirect(name=feature_name, &block)
def redirect(name=feature_name, &block) meth = :"#{name}_redirect" block ||= DEFAULT_REDIRECT_BLOCK define_method(meth, &block) auth_value_methods meth end
def route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
def route(name=feature_name, default=name.to_s.tr('_', '-'), &block) auth_value_method "#{name}_route", default handle_meth = "handle_#{name}" route_meth = :"#{name}_route" before route_meth define_method(handle_meth) do request.is send(route_meth) do before_rodauth instance_exec(request, &block) end end routes << handle_meth end
def session_key(meth, value)
def session_key(meth, value) define_method(meth){convert_session_key(value)} auth_value_methods(meth) end
def view(page, title, name=feature_name)
def view(page, title, name=feature_name) meth = :"#{name}_view" define_method(meth) do view(page, title) end auth_methods meth end