sensu-json 1.1.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +20 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/sensu/json/java.rb +28 -0
- data/lib/sensu/json/oj.rb +29 -0
- data/lib/sensu/json/parse_error.rb +23 -0
- data/lib/sensu/json.rb +49 -0
- data/sensu-json.gemspec +25 -0
- data/spec/json_spec.rb +11 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0e996516b966ed9d95f9db4f449d8ec6dbb313c7
|
4
|
+
data.tar.gz: 4eb015c8f96ab6fff52b27b2c7de059a390a5515
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1999f2e34c8d08284c71cf296d5f4b0904d6337bf0bdbf3f01a125e5266ed4106db014c0996cb69ba337a9f1961d499693bc40c6df1a9ffc45301cb19066a46e
|
7
|
+
data.tar.gz: 2e6ab2768f6c26c040a22fbe41d7b4d47d554c1ce7417ed4291ba22cc80a2c10aab181a823eb9d4260e618c1094930748fa3cd2303525439518d1d9e24561cfb
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2016 Heavy Water Operations, LLC.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Sensu::JSON
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu/sensu-json.svg?branch=master)](https://travis-ci.org/sensu/sensu-json)
|
4
|
+
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu/sensu-json.png)](https://codeclimate.com/github/sensu/sensu-json)
|
6
|
+
[![Code Climate Coverage](https://codeclimate.com/github/sensu/sensu-json/coverage.png)](https://codeclimate.com/github/sensu/sensu-json)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'sensu-json'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
This library provides the Sensu JSON parser abstraction, enabling
|
21
|
+
the use of platform specific JSON parsers. Its documentation can be
|
22
|
+
found [here](http://rubydoc.info/github/sensu/sensu-json/Sensu/JSON).
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
Please do not submit a pull request to add features that Sensu does
|
27
|
+
not nor will not require.
|
28
|
+
|
29
|
+
1. [Fork it](https://github.com/sensu/sensu-json/fork)
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
Sensu JSON is released under the [MIT license](https://raw.github.com/sensu/sensu-json/master/LICENSE.txt).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sensu/json"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Sensu
|
4
|
+
module JSON
|
5
|
+
# The Sensu JSON parser when running on JRuby.
|
6
|
+
class Java
|
7
|
+
# Load (and parse) a JSON string. Sensu expects symbolized keys.
|
8
|
+
#
|
9
|
+
# @param string [String]
|
10
|
+
# @return [Object]
|
11
|
+
def load(string)
|
12
|
+
::JSON.parse(string, :symbolize_names => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Dump (generate) a JSON string from a Ruby object.
|
16
|
+
#
|
17
|
+
# @param object [Object]
|
18
|
+
# @param options [Hash]
|
19
|
+
def dump(object, options={})
|
20
|
+
if options[:pretty]
|
21
|
+
::JSON.pretty_generate(object)
|
22
|
+
else
|
23
|
+
::JSON.fast_generate(object)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
gem "oj", "2.14.6"
|
2
|
+
|
3
|
+
require "oj"
|
4
|
+
|
5
|
+
Oj.default_options = {:mode => :compat}
|
6
|
+
|
7
|
+
module Sensu
|
8
|
+
module JSON
|
9
|
+
# The Sensu JSON parser when running on MRI.
|
10
|
+
class Oj
|
11
|
+
# Load (and parse) a JSON string. Sensu expects symbolized keys.
|
12
|
+
#
|
13
|
+
# @param string [String]
|
14
|
+
# @return [Object]
|
15
|
+
def load(string)
|
16
|
+
::Oj.load(string, :symbol_keys => true)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Dump (generate) a JSON string from a Ruby object.
|
20
|
+
#
|
21
|
+
# @param object [Object]
|
22
|
+
# @param options [Hash]
|
23
|
+
def dump(object, options={})
|
24
|
+
options.merge!(:indent => 2) if options[:pretty]
|
25
|
+
::Oj.dump(object, options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Sensu
|
2
|
+
module JSON
|
3
|
+
# The Sensu JSON parser error abstraction.
|
4
|
+
class ParseError < StandardError
|
5
|
+
attr_reader :data, :cause
|
6
|
+
|
7
|
+
# Produce an encapsulating error for a parser error, maintaining
|
8
|
+
# the backtrace.
|
9
|
+
#
|
10
|
+
# @param original_error [Object]
|
11
|
+
# @param data [Object] (such as a JSON string).
|
12
|
+
def self.build(original_error, data)
|
13
|
+
new(original_error.message).tap do |error|
|
14
|
+
error.instance_eval do
|
15
|
+
@cause = original_error
|
16
|
+
set_backtrace original_error.backtrace
|
17
|
+
@data = data
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/sensu/json.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require "sensu/json/parse_error"
|
2
|
+
|
3
|
+
# Sensu, monitoring for today's infrastructure.
|
4
|
+
module Sensu
|
5
|
+
# The Sensu JSON parser abstraction library.
|
6
|
+
module JSON
|
7
|
+
# The Sensu JSON parser abstraction API.
|
8
|
+
class << self
|
9
|
+
# Set up the JSON parser. This method must be called before any
|
10
|
+
# attempt to use the parser. This method is currently called at
|
11
|
+
# the bottom of this file. The appropriate JSON parser will be
|
12
|
+
# loaded for the current platform.
|
13
|
+
#
|
14
|
+
# @return [Object] parser.
|
15
|
+
def setup!
|
16
|
+
@@parser = case
|
17
|
+
when RUBY_PLATFORM =~ /java/
|
18
|
+
require "sensu/json/java"
|
19
|
+
Sensu::JSON::Java.new
|
20
|
+
else
|
21
|
+
require "sensu/json/oj"
|
22
|
+
Sensu::JSON::Oj.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Load (and parse) a JSON string.
|
27
|
+
#
|
28
|
+
# @param string [String]
|
29
|
+
# @return [Object]
|
30
|
+
def load(string)
|
31
|
+
begin
|
32
|
+
@@parser.load(string)
|
33
|
+
rescue => error
|
34
|
+
raise Sensu::JSON::ParseError.build(error, string)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Dump (generate) a JSON string from a Ruby object.
|
39
|
+
#
|
40
|
+
# @param object [Object]
|
41
|
+
# @param options [Hash]
|
42
|
+
def dump(object, options={})
|
43
|
+
@@parser.dump(object, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Sensu::JSON.setup!
|
data/sensu-json.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "sensu-json"
|
5
|
+
spec.version = "1.1.0"
|
6
|
+
spec.platform = RUBY_PLATFORM =~ /java/ ? Gem::Platform::JAVA : Gem::Platform::RUBY
|
7
|
+
spec.authors = ["Sean Porter"]
|
8
|
+
spec.email = ["portertech@gmail.com"]
|
9
|
+
spec.summary = "The Sensu JSON parser abstraction library"
|
10
|
+
spec.description = "The Sensu JSON parser abstraction library"
|
11
|
+
spec.homepage = "https://github.com/sensu/sensu-json"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency("oj", "2.14.6") unless RUBY_PLATFORM =~ /java/
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
25
|
+
end
|
data/spec/json_spec.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "sensu/json"
|
2
|
+
|
3
|
+
describe "Sensu::JSON" do
|
4
|
+
it "can load a parser for the current platform" do
|
5
|
+
Sensu::JSON.setup!
|
6
|
+
hash = Sensu::JSON.load('{"foo":"bar"}')
|
7
|
+
expect(hash).to eq({:foo => "bar"})
|
8
|
+
string = Sensu::JSON.dump({:baz => "qux"})
|
9
|
+
expect(string).to eq('{"baz":"qux"}')
|
10
|
+
end
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Sean Porter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - "~>"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '1.6'
|
25
|
+
prerelease: false
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
prerelease: false
|
40
|
+
type: :development
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
prerelease: false
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: codeclimate-test-reporter
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
prerelease: false
|
68
|
+
type: :development
|
69
|
+
description: The Sensu JSON parser abstraction library
|
70
|
+
email:
|
71
|
+
- portertech@gmail.com
|
72
|
+
executables:
|
73
|
+
- console
|
74
|
+
- setup
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/sensu/json.rb
|
87
|
+
- lib/sensu/json/java.rb
|
88
|
+
- lib/sensu/json/oj.rb
|
89
|
+
- lib/sensu/json/parse_error.rb
|
90
|
+
- sensu-json.gemspec
|
91
|
+
- spec/json_spec.rb
|
92
|
+
homepage: https://github.com/sensu/sensu-json
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.8
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: The Sensu JSON parser abstraction library
|
116
|
+
test_files:
|
117
|
+
- spec/json_spec.rb
|