Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
Remove some trailing spaces and bad grammar.
  • Loading branch information
libc committed Dec 11, 2012
1 parent 7f00c97 commit acf0787
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
9 changes: 5 additions & 4 deletions lib/tidy_ffi/interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions lib/tidy_ffi/options_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -87,4 +87,4 @@ def method_missing(meth, *args)
@obj.send(meth, *args)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/simple_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit acf0787

Please sign in to comment.