jexp 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def to_jexp
3
+ map {|v| JEXP.jexp(v) }
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class Hash
2
+ def to_jexp
3
+ inject(self::class.new) do |h, (key, value)|
4
+ h.update key.to_s => JEXP.jexp(value)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ class Integer
2
+ def to_jexp() self end
3
+ end
@@ -0,0 +1,3 @@
1
+ class String
2
+ def to_jexp() self end
3
+ end
data/lib/jexp/model.rb ADDED
@@ -0,0 +1,8 @@
1
+ module JEXP
2
+ module Model
3
+ def new(attrs = {})
4
+ sattrs = attrs.inject({}) {|h,(k,v)| h.update(k.to_s => v) }
5
+ super(*members.map {|m| sattrs.delete(m) })
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ module JEXP
2
+ module Resource
3
+ extend Forwardable
4
+
5
+ def_delegator :to_hash, :to_jexp
6
+ def_delegator :to_jexp, :to_json
7
+
8
+ def self.included(receiver)
9
+ receiver.extend Model
10
+ end
11
+
12
+ def to_hash
13
+ members.zip(values).inject({}) {|h,(k,v)| h.update(k => v) }
14
+ end
15
+ end
16
+ end
data/lib/jexp.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+ require 'forwardable'
3
+
4
+ module JEXP
5
+ def self.jexp(*a)
6
+ return *a.map {|o| o.respond_to?(:to_jexp) ? o.to_jexp : JSON.parse(JSON.dump([o])).first }
7
+ end
8
+ end
9
+
10
+ require 'jexp/ext/array'
11
+ require 'jexp/ext/hash'
12
+ require 'jexp/ext/integer'
13
+ require 'jexp/ext/string'
14
+ require 'jexp/model'
15
+ require 'jexp/resource'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jexp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.pre
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-08 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email:
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - lib/jexp/ext/array.rb
35
+ - lib/jexp/ext/hash.rb
36
+ - lib/jexp/ext/integer.rb
37
+ - lib/jexp/ext/string.rb
38
+ - lib/jexp/model.rb
39
+ - lib/jexp/resource.rb
40
+ - lib/jexp.rb
41
+ has_rdoc: true
42
+ homepage:
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.3.1
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.5
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: a simple library for working with JSON
69
+ test_files: []
70
+