Module: Backtastic

Defined in:
lib/backtastic.rb,
lib/backtastic/version.rb

Defined Under Namespace

Classes: BacktasticEngine

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.options_from(validator) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/backtastic.rb', line 22

def self.options_from(validator)
  options = validator.options.dup
  options.each do |option, value|
    options[option] = value.is_a?(Regexp) ? value.inspect : value
  end
  options
end

.validations_for(model) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/backtastic.rb', line 11

def self.validations_for(model)
  validations = {}
	model.validators.each do |validator|
    attribute = validator.attributes.first
    validator_type = validator.class.to_s.gsub(/^ActiveModel::Validations::/, "").gsub(/Validator$/, "").downcase
    validations[attribute] ||= {}
    validations[attribute][validator_type] = options_from(validator)
  end
  validations
end