jsonify 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -10
- data/lib/jsonify.rb +1 -1
- data/lib/jsonify/blank_slate.rb +109 -0
- data/lib/jsonify/version.rb +1 -1
- metadata +18 -18
- data/lib/blank_slate.rb +0 -109
data/README.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
# Jsonify — a builder for JSON [](http://travis-ci.org/bsiggelkow/jsonify)
|
2
2
|
|
3
3
|
[Jsonify](https://github.com/bsiggelkow/jsonify) is to JSON as [Builder](https://github.com/jimweirich/builder) is to XML.
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
If you want to use Jsonify for Rails templates, install [Jsonify-Rails](https://github.com/bsiggelkow/jsonify-rails).
|
6
6
|
|
7
7
|
## Goal
|
8
8
|
|
9
9
|
Jsonify provides a ___builder___ style engine for creating correct JSON representations of Ruby objects.
|
10
10
|
|
11
|
-
[Jsonify-Rails](http://github.com/bsiggelkow/jsonify-rails) hooks into Rails ActionView to allow you to create JSON view templates in much the same way that you can use Builder for XML templates.
|
12
|
-
|
13
11
|
## Motivation
|
14
12
|
|
15
13
|
JSON and XML are without a doubt the most common representations used by RESTful applications. Jsonify was built around the notion that these representations belong in the ___view___ layer of the application.
|
@@ -368,12 +366,7 @@ In this case, Jsonify decides from the first line that you are creating a JSON o
|
|
368
366
|
|
369
367
|
## TODOs
|
370
368
|
1. Benchmark performance
|
371
|
-
1.
|
372
|
-
|
373
|
-
## Roadmap
|
374
|
-
|
375
|
-
1. Split Rails template handling into separate gem
|
376
|
-
1. Add support for Sinatra and Padrino (Tilt integration?)
|
369
|
+
1. Tilt Integration (jsonify-tilt)
|
377
370
|
|
378
371
|
## License
|
379
372
|
|
data/lib/jsonify.rb
CHANGED
@@ -0,0 +1,109 @@
|
|
1
|
+
######################################################################
|
2
|
+
# Jsonify::BlankSlate is based on Jim Weirich's BlankSlate.
|
3
|
+
#
|
4
|
+
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# BlankSlate provides an abstract base class with no predefined
|
8
|
+
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
9
|
+
# BlankSlate is useful as a base class when writing classes that
|
10
|
+
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
11
|
+
#
|
12
|
+
# This Jsonify implementation of BlankSlate is identical; with the
|
13
|
+
# exception that it does not include the Kernel, Module, and Object
|
14
|
+
# patches.
|
15
|
+
#
|
16
|
+
module Jsonify
|
17
|
+
class BlankSlate
|
18
|
+
class << self
|
19
|
+
|
20
|
+
# Hide the method named +name+ in the BlankSlate class. Don't
|
21
|
+
# hide +instance_eval+ or any method beginning with "__".
|
22
|
+
def hide(name)
|
23
|
+
if instance_methods.include?(name.to_s) and
|
24
|
+
name !~ /^(__|instance_eval)/
|
25
|
+
@hidden_methods ||= {}
|
26
|
+
@hidden_methods[name.to_sym] = instance_method(name)
|
27
|
+
undef_method name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_hidden_method(name)
|
32
|
+
@hidden_methods ||= {}
|
33
|
+
@hidden_methods[name] || superclass.find_hidden_method(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Redefine a previously hidden method so that it may be called on a blank
|
37
|
+
# slate object.
|
38
|
+
def reveal(name)
|
39
|
+
hidden_method = find_hidden_method(name)
|
40
|
+
fail "Don't know how to reveal method '#{name}'" unless hidden_method
|
41
|
+
define_method(name, hidden_method)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
instance_methods.each { |m| hide(m) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
######################################################################
|
49
|
+
# Since Ruby is very dynamic, methods added to the ancestors of
|
50
|
+
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
|
51
|
+
# list of available BlankSlate methods. We handle this by defining a
|
52
|
+
# hook in the Object and Kernel classes that will hide any method
|
53
|
+
# defined after BlankSlate has been loaded.
|
54
|
+
#
|
55
|
+
# module Kernel
|
56
|
+
# class << self
|
57
|
+
# alias_method :blank_slate_method_added, :method_added
|
58
|
+
#
|
59
|
+
# # Detect method additions to Kernel and remove them in the
|
60
|
+
# # BlankSlate class.
|
61
|
+
# def method_added(name)
|
62
|
+
# result = blank_slate_method_added(name)
|
63
|
+
# return result if self != Kernel
|
64
|
+
# BlankSlate.hide(name)
|
65
|
+
# result
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
|
70
|
+
######################################################################
|
71
|
+
# Same as above, except in Object.
|
72
|
+
#
|
73
|
+
# class Object
|
74
|
+
# class << self
|
75
|
+
# alias_method :blank_slate_method_added, :method_added
|
76
|
+
#
|
77
|
+
# # Detect method additions to Object and remove them in the
|
78
|
+
# # BlankSlate class.
|
79
|
+
# def method_added(name)
|
80
|
+
# result = blank_slate_method_added(name)
|
81
|
+
# return result if self != Object
|
82
|
+
# BlankSlate.hide(name)
|
83
|
+
# result
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# def find_hidden_method(name)
|
87
|
+
# nil
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
# end
|
91
|
+
|
92
|
+
######################################################################
|
93
|
+
# Also, modules included into Object need to be scanned and have their
|
94
|
+
# instance methods removed from blank slate. In theory, modules
|
95
|
+
# included into Kernel would have to be removed as well, but a
|
96
|
+
# "feature" of Ruby prevents late includes into modules from being
|
97
|
+
# exposed in the first place.
|
98
|
+
#
|
99
|
+
# class Module
|
100
|
+
# alias blankslate_original_append_features append_features
|
101
|
+
# def append_features(mod)
|
102
|
+
# result = blankslate_original_append_features(mod)
|
103
|
+
# return result if mod != Object
|
104
|
+
# instance_methods.each do |name|
|
105
|
+
# BlankSlate.hide(name)
|
106
|
+
# end
|
107
|
+
# result
|
108
|
+
# end
|
109
|
+
# end
|
data/lib/jsonify/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-08-02 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &70365091068360 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70365091068360
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70365091067280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70365091067280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70365091066160 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70365091066160
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70365091065240 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70365091065240
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: autotest
|
60
|
-
requirement: &
|
60
|
+
requirement: &70365091063920 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70365091063920
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: yard
|
71
|
-
requirement: &
|
71
|
+
requirement: &70365091062820 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70365091062820
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rdiscount
|
82
|
-
requirement: &
|
82
|
+
requirement: &70365091061600 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70365091061600
|
91
91
|
description: Turn Ruby objects into JSON -- correctly!
|
92
92
|
email:
|
93
93
|
- bsiggelkow@me.com
|
@@ -102,8 +102,8 @@ files:
|
|
102
102
|
- README.md
|
103
103
|
- Rakefile
|
104
104
|
- jsonify.gemspec
|
105
|
-
- lib/blank_slate.rb
|
106
105
|
- lib/jsonify.rb
|
106
|
+
- lib/jsonify/blank_slate.rb
|
107
107
|
- lib/jsonify/builder.rb
|
108
108
|
- lib/jsonify/generate.rb
|
109
109
|
- lib/jsonify/json_value.rb
|
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
segments:
|
129
129
|
- 0
|
130
|
-
hash:
|
130
|
+
hash: -3226176864107262675
|
131
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
132
|
none: false
|
133
133
|
requirements:
|
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
136
|
version: '0'
|
137
137
|
segments:
|
138
138
|
- 0
|
139
|
-
hash:
|
139
|
+
hash: -3226176864107262675
|
140
140
|
requirements: []
|
141
141
|
rubyforge_project: jsonify
|
142
142
|
rubygems_version: 1.8.6
|
data/lib/blank_slate.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#--
|
3
|
-
# Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
|
4
|
-
# All rights reserved.
|
5
|
-
|
6
|
-
# Permission is granted for use, copying, modification, distribution,
|
7
|
-
# and distribution of modified versions of this work as long as the
|
8
|
-
# above copyright notice is included.
|
9
|
-
#++
|
10
|
-
|
11
|
-
######################################################################
|
12
|
-
# BlankSlate provides an abstract base class with no predefined
|
13
|
-
# methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
|
14
|
-
# BlankSlate is useful as a base class when writing classes that
|
15
|
-
# depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
|
16
|
-
#
|
17
|
-
class BlankSlate
|
18
|
-
class << self
|
19
|
-
|
20
|
-
# Hide the method named +name+ in the BlankSlate class. Don't
|
21
|
-
# hide +instance_eval+ or any method beginning with "__".
|
22
|
-
def hide(name)
|
23
|
-
if instance_methods.include?(name.to_s) and
|
24
|
-
name !~ /^(__|instance_eval)/
|
25
|
-
@hidden_methods ||= {}
|
26
|
-
@hidden_methods[name.to_sym] = instance_method(name)
|
27
|
-
undef_method name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def find_hidden_method(name)
|
32
|
-
@hidden_methods ||= {}
|
33
|
-
@hidden_methods[name] || superclass.find_hidden_method(name)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Redefine a previously hidden method so that it may be called on a blank
|
37
|
-
# slate object.
|
38
|
-
def reveal(name)
|
39
|
-
hidden_method = find_hidden_method(name)
|
40
|
-
fail "Don't know how to reveal method '#{name}'" unless hidden_method
|
41
|
-
define_method(name, hidden_method)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
instance_methods.each { |m| hide(m) }
|
46
|
-
end
|
47
|
-
|
48
|
-
######################################################################
|
49
|
-
# Since Ruby is very dynamic, methods added to the ancestors of
|
50
|
-
# BlankSlate <em>after BlankSlate is defined</em> will show up in the
|
51
|
-
# list of available BlankSlate methods. We handle this by defining a
|
52
|
-
# hook in the Object and Kernel classes that will hide any method
|
53
|
-
# defined after BlankSlate has been loaded.
|
54
|
-
#
|
55
|
-
module Kernel
|
56
|
-
class << self
|
57
|
-
alias_method :blank_slate_method_added, :method_added
|
58
|
-
|
59
|
-
# Detect method additions to Kernel and remove them in the
|
60
|
-
# BlankSlate class.
|
61
|
-
def method_added(name)
|
62
|
-
result = blank_slate_method_added(name)
|
63
|
-
return result if self != Kernel
|
64
|
-
BlankSlate.hide(name)
|
65
|
-
result
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
######################################################################
|
71
|
-
# Same as above, except in Object.
|
72
|
-
#
|
73
|
-
class Object
|
74
|
-
class << self
|
75
|
-
alias_method :blank_slate_method_added, :method_added
|
76
|
-
|
77
|
-
# Detect method additions to Object and remove them in the
|
78
|
-
# BlankSlate class.
|
79
|
-
def method_added(name)
|
80
|
-
result = blank_slate_method_added(name)
|
81
|
-
return result if self != Object
|
82
|
-
BlankSlate.hide(name)
|
83
|
-
result
|
84
|
-
end
|
85
|
-
|
86
|
-
def find_hidden_method(name)
|
87
|
-
nil
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
######################################################################
|
93
|
-
# Also, modules included into Object need to be scanned and have their
|
94
|
-
# instance methods removed from blank slate. In theory, modules
|
95
|
-
# included into Kernel would have to be removed as well, but a
|
96
|
-
# "feature" of Ruby prevents late includes into modules from being
|
97
|
-
# exposed in the first place.
|
98
|
-
#
|
99
|
-
class Module
|
100
|
-
alias blankslate_original_append_features append_features
|
101
|
-
def append_features(mod)
|
102
|
-
result = blankslate_original_append_features(mod)
|
103
|
-
return result if mod != Object
|
104
|
-
instance_methods.each do |name|
|
105
|
-
BlankSlate.hide(name)
|
106
|
-
end
|
107
|
-
result
|
108
|
-
end
|
109
|
-
end
|