Permalink
Browse files

Code cleanup.

Remove some trailing spaces and bad grammar.
  • Loading branch information...
1 parent 7f00c97 commit acf07874197d496381fe34916240836cad134f00 @libc committed Dec 11, 2012
Showing with 13 additions and 12 deletions.
  1. +5 −4 lib/tidy_ffi/interface.rb
  2. +7 −7 lib/tidy_ffi/options_container.rb
  3. +1 −1 spec/simple_spec.rb
@@ -111,7 +111,7 @@ def pick_list_for(opt)
pick_list
end
private :pick_list_for
-
+
# Loads default options.
def load_default_options
return if @default_options
@@ -171,11 +171,12 @@ def load_default_options
def self.default_options
@default_options ||= load_default_options
end
-
+
# Returns true if value is valid for +option+ and false otherwise.
def self.option_valid?(option, value)
- return false unless spec = default_options[option]
-
+ spec = default_options[option]
+ return false unless spec
+
case spec[:type]
when :boolean
true == value || false == value || value == 0 || value == 1 || %w(on off true false 0 1 yes no).include?(value.downcase)
@@ -48,12 +48,12 @@ def method_missing(method, *args)
# It's a kinda bad method: it uses TidyFFI::Interface.option_valid and TidyFFI::Tidy.validate_options?
# Also it do second lookup into default options
def validate_option(key, value)
- if TidyFFI::Tidy.validate_options? && !TidyFFI::Interface.option_valid?(key, value)
- if TidyFFI::Interface.default_options[key]
- raise TidyFFI::Tidy::InvalidOptionValue, "#{value} is not valid for #{key}"
- else
- raise TidyFFI::Tidy::InvalidOptionName, "#{key} is invalid option name"
- end
+ return if !TidyFFI::Tidy.validate_options? || TidyFFI::Interface.option_valid?(key, value)
+
+ if TidyFFI::Interface.default_options[key]
+ raise TidyFFI::Tidy::InvalidOptionValue, "#{value} is not a valid value for key #{key}"
+ else
+ raise TidyFFI::Tidy::InvalidOptionName, "#{key} is an invalid option name"
end
end
@@ -87,4 +87,4 @@ def method_missing(meth, *args)
@obj.send(meth, *args)
end
end
-end
+end
View
@@ -46,7 +46,7 @@
it "raises error on invalid option value" do
TidyFFI::Tidy.validate_options = true
lambda do
- TidyFFI::Tidy.default_options = {:force_output => "utter trash"}
+ TidyFFI::Tidy.default_options = {:force_output => "utter garbage"}
end.should raise_error(TidyFFI::Tidy::InvalidOptionValue)
end
end

0 comments on commit acf0787

Please sign in to comment.