lib/refcode/encodable.rb in refcode-0.1.1 vs lib/refcode/encodable.rb in refcode-0.1.2

- old
+ new

@@ -29,24 +29,27 @@ private def encoder Refcode::Encoder.new do |r| check_refcode_options! - r.secret = self.class.refcode_options[:secret] - salt_option = self.class.refcode_options[:salt] - if salt_option.respond_to? :call - r.salt = salt_option.call self - elsif salt_option.is_a? Symbol - r.salt = self.send salt_option - else - r.salt = salt_option - end + r.secret = get_option_value(self.class.refcode_options[:secret]) + r.salt = get_option_value(self.class.refcode_options[:salt]) raise "Value for salt is nil (#{salt_option} given)" if r.salt.nil? end end def check_refcode_options! raise RefcodeInitException.new('You must call the has_refcode method in your class definition') unless self.class.refcode_options + end + + def get_option_value option + if option.respond_to? :call + option.call self + elsif option.is_a? Symbol + self.send option + else + option + end end end end