summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2011-03-22 18:49:03 -0700
committerDaniel DeLeo <dan@opscode.com>2011-03-22 18:49:03 -0700
commit60b555b60040059ecbfe327766c1d4609227f4e8 (patch)
treeb7fcee18f830af0d86d9e2c5c87d670c07e7e287
parent2589ac6fce8410b30949b5016c3eb5533353a443 (diff)
downloadohai-60b555b60040059ecbfe327766c1d4609227f4e8.tar.gz
Switched ohai to yajl. remove ability to serialize Ohai::System
serializing feature had no tests, is not used in chef. plus, you can just serialize the @data hash.
-rw-r--r--Rakefile4
-rw-r--r--lib/ohai/system.rb36
2 files changed, 10 insertions, 30 deletions
diff --git a/Rakefile b/Rakefile
index 529fd52b..97919e35 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,7 +5,7 @@ require 'date'
require 'spec/rake/spectask'
GEM = "ohai"
-GEM_VERSION = "0.5.9"
+GEM_VERSION = "0.6.0.beta.0"
AUTHOR = "Adam Jacob"
EMAIL = "adam@opscode.com"
HOMEPAGE = "http://wiki.opscode.com/display/ohai"
@@ -22,7 +22,7 @@ spec = Gem::Specification.new do |s|
s.email = EMAIL
s.homepage = HOMEPAGE
- s.add_dependency "json", ">= 1.4.4", "<= 1.4.6"
+ s.add_dependency "yajl-ruby", "~> 0.7.8"
s.add_dependency "extlib"
s.add_dependency "systemu"
s.add_dependency "mixlib-cli"
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index 309ede1c..141f3faa 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -22,16 +22,7 @@ require 'ohai/mixin/from_file'
require 'ohai/mixin/command'
require 'ohai/mixin/string'
-begin
- require 'json'
-rescue LoadError
- begin
- require 'json/pure'
- rescue LoadError
- STDERR.puts "No valid JSON library detected, please install one of 'json' or 'json_pure'."
- exit -2
- end
-end
+require 'yajl'
module Ohai
class System
@@ -213,42 +204,31 @@ module Ohai
alias :_require_plugin :require_plugin
# Serialize this object as a hash
- def to_json(*a)
- output = @data.clone
- output["json_class"] = self.class.name
- output.to_json(*a)
+ def to_json
+ Yajl::Encoder.new.encode(@data)
end
# Pretty Print this object as JSON
- def json_pretty_print
- JSON.pretty_generate(@data)
+ def json_pretty_print(item=nil)
+ Yajl::Encoder.new(:pretty => true).encode(item || @data)
end
def attributes_print(a)
raise ArgumentError, "I cannot find an attribute named #{a}!" unless @data.has_key?(a)
case a
when Hash,Mash,Array
- JSON.pretty_generate(@data[a])
+ json_pretty_print(@data[a])
when String
if @data[a].respond_to?(:lines)
- JSON.pretty_generate(@data[a].lines.to_a)
+ json_pretty_print(@data[a].lines.to_a)
else
- JSON.pretty_generate(@data[a].to_a)
+ json_pretty_print(@data[a].to_a)
end
else
raise ArgumentError, "I can only generate JSON for Hashes, Mashes, Arrays and Strings. You fed me a #{@data[a].class}!"
end
end
- # Create an Ohai::System from JSON
- def self.json_create(o)
- ohai = new
- o.each do |key, value|
- ohai.data[key] = value unless key == "json_class"
- end
- ohai
- end
-
def method_missing(name, *args)
return get_attribute(name) if args.length == 0