lib/usher/route/variable.rb in joshbuddy-usher-0.4.2 vs lib/usher/route/variable.rb in joshbuddy-usher-0.4.3

- old
+ new

@@ -1,36 +1,22 @@ class Usher class Route class Variable - attr_reader :type, :name, :validator, :transformer, :regex_matcher + attr_reader :type, :name, :validator, :regex_matcher attr_accessor :look_ahead, :globs_capture_separators - def initialize(type, name, validator = nil, transformer = nil, regex_matcher = nil, globs_capture_separators = false) + def initialize(type, name, validator = nil, regex_matcher = nil, globs_capture_separators = false) @type = type @name = :"#{name}" @validator = validator - @transformer = transformer @regex_matcher = regex_matcher @globs_capture_separators = globs_capture_separators end def to_s "#{type}#{name}" end - def transform!(val) - return val unless @transformer - - case @transformer - when Proc - @transformer.call(val) - when Symbol - val.send(@transformer) - end - rescue Exception => e - raise ValidationException.new("#{val} could not be successfully transformed by #{@transformer}, root cause #{e.inspect}") - end - def valid!(val) case @validator when Proc @validator.call(val) else \ No newline at end of file