module LightParams::PropertiesConfiguration::ClassMethods

Public Instance Methods

config() click to toggle source
# File lib/light_params/properties_configuration.rb, line 11
def config
  @config ||= {}
end
properties(*prop_names) click to toggle source
# File lib/light_params/properties_configuration.rb, line 15
def properties(*prop_names)
  opts = prop_names.last.is_a?(Hash) ? prop_names.pop : nil
  prop_names.each do |prop_name|
    _add_property(prop_name)
    _add_property_modifications(prop_name, opts || {})
  end
end
property(prop_name, options = {}, &block) click to toggle source
# File lib/light_params/properties_configuration.rb, line 23
def property(prop_name, options = {}, &block)
  _add_property(prop_name)
  _add_property_modifications(prop_name, options)
  _add_property_validation(prop_name, options[:validates]) if options[:validates]
  _add_property_source(prop_name, &block) if block
end

Private Instance Methods

_add_property(prop_name) click to toggle source
# File lib/light_params/properties_configuration.rb, line 62
def _add_property(prop_name)
  return unless _properties.add?(prop_name)
  define_method(prop_name) { |&block| self.[](prop_name, &block) }
  property_assignment = "#{prop_name}=".to_sym
  define_method(property_assignment) { |value| self.[]=(prop_name, value) }
end
_add_property_modifications(prop_name, options = {}) click to toggle source
# File lib/light_params/properties_configuration.rb, line 56
def _add_property_modifications(prop_name, options = {})
  modifications = options.slice(:from, :with, :default, :model, :collection, :uniq, :compact, :required)
  return if modifications.empty?
  _properties_modifications[prop_name] = modifications
end
_add_property_source(prop_name, &block) click to toggle source
# File lib/light_params/properties_configuration.rb, line 32
def _add_property_source(prop_name, &block)
  klass = Class.new(self)
  klass.instance_variable_set(:@config, {})
  klass.instance_variable_set(:@name, ActiveSupport::Inflector.classify(prop_name))
  klass.class_eval(&block)
  _properties_sources[prop_name] = { class: klass }
end
_add_property_validation(prop_name, validation) click to toggle source
# File lib/light_params/properties_configuration.rb, line 69
def _add_property_validation(prop_name, validation)
  _validations[prop_name] = validation
end
_properties() click to toggle source
# File lib/light_params/properties_configuration.rb, line 48
def _properties
  config[:properties] ||= Set.new
end
_properties_modifications() click to toggle source
# File lib/light_params/properties_configuration.rb, line 44
def _properties_modifications
  config[:properties_modifications] ||= {}
end
_properties_sources() click to toggle source
# File lib/light_params/properties_configuration.rb, line 40
def _properties_sources
  config[:properties_sources] ||= {}
end
_validations() click to toggle source
# File lib/light_params/properties_configuration.rb, line 52
def _validations
  config[:validations] ||= {}
end