lib/remarkable/dsl/matches.rb in remarkable-3.0.1 vs lib/remarkable/dsl/matches.rb in remarkable-3.0.2

- old
+ new

@@ -47,82 +47,82 @@ # def default_options {} end - # Overwrites default_i18n_options to provide arguments and optionals - # to interpolation options. - # - # If you still need to provide more other interpolation options, you can - # do that in two ways: - # - # 1. Overwrite interpolation_options: - # - # def interpolation_options - # { :real_value => real_value } - # end - # - # 2. Return a hash from your assertion method: - # - # def my_assertion - # return true if real_value == expected_value - # return false, :real_value => real_value - # end - # + # Overwrites default_i18n_options to provide arguments and optionals + # to interpolation options. + # + # If you still need to provide more other interpolation options, you can + # do that in two ways: + # + # 1. Overwrite interpolation_options: + # + # def interpolation_options + # { :real_value => real_value } + # end + # + # 2. Return a hash from your assertion method: + # + # def my_assertion + # return true if real_value == expected_value + # return false, :real_value => real_value + # end + # # In both cases, :real_value will be available as interpolation option. # def default_i18n_options #:nodoc: - i18n_options = {} - - @options.each do |key, value| - i18n_options[key] = value.inspect - end if @options - + i18n_options = {} + + @options.each do |key, value| + i18n_options[key] = value.inspect + end if @options + # Also add arguments as interpolation options. self.class.matcher_arguments[:names].each do |name| i18n_options[name] = instance_variable_get("@#{name}").inspect - end - - # Add collection interpolation options. - i18n_options.update(collection_interpolation) - - # Add default options (highest priority). They should not be overwritten. + end + + # Add collection interpolation options. + i18n_options.update(collection_interpolation) + + # Add default options (highest priority). They should not be overwritten. i18n_options.update(super) - end - - # Method responsible to add collection as interpolation. - # - def collection_interpolation #:nodoc: - options = {} - + end + + # Method responsible to add collection as interpolation. + # + def collection_interpolation #:nodoc: + options = {} + if collection_name = self.class.matcher_arguments[:collection] collection_name = collection_name.to_sym collection = instance_variable_get("@#{collection_name}") options[collection_name] = array_to_sentence(collection) if collection object_name = self.class.matcher_arguments[:as].to_sym object = instance_variable_get("@#{object_name}") options[object_name] = object if object - end - - options + end + + options end - # Send the assertion methods given and create a expectation message - # if any of those methods returns false. - # - # Since most assertion methods ends with an question mark and it's not - # readable in yml files, we remove question and exclation marks at the - # end of the method name before translating it. So if you have a method - # called is_valid? on I18n yml file we will check for a key :is_valid. + # Send the assertion methods given and create a expectation message + # if any of those methods returns false. # + # Since most assertion methods ends with an question mark and it's not + # readable in yml files, we remove question and exclation marks at the + # end of the method name before translating it. So if you have a method + # called is_valid? on I18n yml file we will check for a key :is_valid. + # def send_methods_and_generate_message(methods) #:nodoc: methods.each do |method| - bool, hash = send(method) + bool, hash = send(method) - unless bool - @expectation ||= Remarkable.t "expectations.#{method.to_s.gsub(/(\?|\!)$/, '')}", - default_i18n_options.merge(hash || {}) + unless bool + @expectation ||= Remarkable.t "expectations.#{method.to_s.gsub(/(\?|\!)$/, '')}", + default_i18n_options.merge(hash || {}) return false end end return true