apjson 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -11,7 +11,7 @@ apjson should work identically on:
11
11
 
12
12
  == Install
13
13
 
14
- You can install okuyama by gem.
14
+ You can install apjson by gem.
15
15
  gem install apjson
16
16
 
17
17
  == Usage
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
data/apjson.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "apjson"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["haracane"]
12
- s.date = "2012-11-30"
12
+ s.date = "2012-12-09"
13
13
  s.description = "print parsed json with your favorite format"
14
14
  s.email = "haracane@gmail.com"
15
15
  s.executables = ["apjson"]
@@ -28,7 +28,8 @@ Gem::Specification.new do |s|
28
28
  "apjson.gemspec",
29
29
  "bin/apjson",
30
30
  "lib/apjson.rb",
31
- "spec/apjson_spec.rb",
31
+ "spec/bin/apjson_spec.rb",
32
+ "spec/lib/apjson_spec.rb",
32
33
  "spec/spec_helper.rb"
33
34
  ]
34
35
  s.homepage = "http://github.com/haracane/apjson"
data/lib/apjson.rb CHANGED
@@ -1,2 +1,25 @@
1
+ require "rubygems"
2
+ require "logger"
3
+ require "json"
4
+
1
5
  module Apjson
6
+ def self.logger
7
+ @logger ||= (rails_logger || default_logger)
8
+ end
9
+
10
+ def self.rails_logger
11
+ (defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger) ||
12
+ (defined?(RAILS_DEFAULT_LOGGER) && RAILS_DEFAULT_LOGGER.respond_to?(:debug) && RAILS_DEFAULT_LOGGER)
13
+ end
14
+
15
+ def self.default_logger
16
+ require 'logger'
17
+ l = Logger.new(STDERR)
18
+ l.level = Logger::INFO
19
+ l
20
+ end
21
+
22
+ def self.logger=(logger)
23
+ @logger = logger
24
+ end
2
25
  end
@@ -0,0 +1,62 @@
1
+ require "spec_helper"
2
+
3
+ describe "bin/apjson" do
4
+ input = [0,1,{"key"=>"val"}].to_json
5
+ context "when option is not set" do
6
+ context "when input is '#{input}'" do
7
+ it "should print json with awesome_print" do
8
+ result = `echo '#{input}' | #{Apjson::RUBY_CMD} #{Apjson::BIN_DIR}/apjson`
9
+ result.should =~ /\[0\]/
10
+ result.should =~ /\[1\]/
11
+ result.should =~ /\[2\]/
12
+ result.should =~ /0,/
13
+ result.should =~ /1,/
14
+ result.should =~ /"key" => "val"/
15
+ end
16
+ end
17
+
18
+ end
19
+
20
+ context "when using --p option" do
21
+ context "when input is '#{input}'" do
22
+ it "should print json with p" do
23
+ result = `echo '#{input}' | #{Apjson::RUBY_CMD} #{Apjson::BIN_DIR}/apjson --p`
24
+ result.chomp!
25
+ result.should == "[0, 1, {\"key\"=>\"val\"}]"
26
+ end
27
+ end
28
+ end
29
+
30
+ context "when using --pp option" do
31
+ context "when input is '#{input}'" do
32
+ it "should print json with PrettyPrint" do
33
+ result = `echo '#{input}' | #{Apjson::RUBY_CMD} #{Apjson::BIN_DIR}/apjson --pp`
34
+ result.chomp!
35
+ result.should == "[0, 1, {\"key\"=>\"val\"}]"
36
+ end
37
+ end
38
+ end
39
+
40
+ context "when using --puts option" do
41
+ context "when input is '#{input}'" do
42
+ context "when argument is not set" do
43
+ it "should print json with puts" do
44
+ result = `echo '#{input}' | #{Apjson::RUBY_CMD} #{Apjson::BIN_DIR}/apjson --puts`
45
+ result = result.split()
46
+ result.shift.should == "0"
47
+ result.shift.should == "1"
48
+ result.shift.should == "keyval"
49
+ result.size.should == 0
50
+ end
51
+ end
52
+ context "when argument is \"2 key\"" do
53
+ it "should print \"val\"" do
54
+ result = `echo '#{input}' | #{Apjson::RUBY_CMD} #{Apjson::BIN_DIR}/apjson --puts 2 key`
55
+ result.chomp!
56
+ result.should == "val"
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,6 @@
1
+ require "spec_helper"
2
+
3
+ describe "Apjson" do
4
+ it "should success" do
5
+ end
6
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'apjson'
5
+ require "tempfile"
5
6
 
6
7
  # Requires supporting files with custom matchers and macros, etc,
7
8
  # in ./support/ and its subdirectories.
@@ -10,3 +11,20 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
11
  RSpec.configure do |config|
11
12
 
12
13
  end
14
+
15
+ module Apjson
16
+ APJSON_HOME = File.expand_path(File.dirname(__FILE__) + "/..")
17
+ BIN_DIR = "#{APJSON_HOME}/bin"
18
+ LIB_DIR = "#{APJSON_HOME}/lib"
19
+ RUBY_CMD = "/usr/bin/env ruby -I #{LIB_DIR}"
20
+ REDIRECT = {:stderr=>"2> /dev/null"}
21
+ end
22
+
23
+ Apjson.logger = Logger.new(STDERR)
24
+ if File.exist?('/tmp/Apjson.debug') then
25
+ Apjson.logger.level = Logger::DEBUG
26
+ Apjson::REDIRECT[:stderr] = nil
27
+ else
28
+ Apjson.logger.level = Logger::ERROR
29
+ Apjson::REDIRECT[:stderr] = "2> /dev/null"
30
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apjson
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - haracane
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-30 00:00:00 Z
18
+ date: 2012-12-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: json
@@ -140,7 +140,8 @@ files:
140
140
  - apjson.gemspec
141
141
  - bin/apjson
142
142
  - lib/apjson.rb
143
- - spec/apjson_spec.rb
143
+ - spec/bin/apjson_spec.rb
144
+ - spec/lib/apjson_spec.rb
144
145
  - spec/spec_helper.rb
145
146
  homepage: http://github.com/haracane/apjson
146
147
  licenses:
data/spec/apjson_spec.rb DELETED
@@ -1,6 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "Apjson" do
4
- it "succeed" do
5
- end
6
- end