Skip to content

Commit

Permalink
Added the Tire::Configuration.pretty option for JSON output
Browse files Browse the repository at this point in the history
* The option is set to `true` by default
* Pass a truthy value to set the option to "true" or false/nil or false/nil to set the option to "false"
  • Loading branch information
karmi committed Sep 22, 2012
1 parent 4132c1e commit 95acfae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/tire/configuration.rb
Expand Up @@ -19,6 +19,14 @@ def self.logger(device=nil, options={})
@logger || nil
end

def self.pretty(value=nil, options={})
if value === false
return @pretty = false
else
@pretty.nil? ? true : @pretty
end
end

def self.reset(*properties)
reset_variables = properties.empty? ? instance_variables : instance_variables.map { |p| p.to_s} & \
properties.map { |p| "@#{p}" }
Expand Down
10 changes: 10 additions & 0 deletions test/unit/configuration_test.rb
Expand Up @@ -52,6 +52,16 @@ def teardown
assert_instance_of Tire::Logger, Configuration.logger
end

should "set pretty option to true by default" do
assert_not_nil Configuration.pretty
assert Configuration.pretty, "Should be true, but is: #{Configuration.pretty.inspect}"
end

should "set the pretty option to false" do
Configuration.pretty(false)
assert ! Configuration.pretty, "Should be falsy, but is: #{Configuration.pretty.inspect}"
end

should "allow to reset the configuration for specific property" do
Configuration.url 'http://example.com'
assert_equal 'http://example.com', Configuration.url
Expand Down

0 comments on commit 95acfae

Please sign in to comment.