json_object 0.0.1

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.
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use default@json_object --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Gem's dependencies specified in json_object.gemspec
4
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ json_object (0.0.1)
5
+ activesupport
6
+ i18n
7
+ json
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activesupport (3.0.10)
13
+ diff-lcs (1.1.3)
14
+ i18n (0.6.0)
15
+ json (1.5.3)
16
+ rspec (2.6.0)
17
+ rspec-core (~> 2.6.0)
18
+ rspec-expectations (~> 2.6.0)
19
+ rspec-mocks (~> 2.6.0)
20
+ rspec-core (2.6.4)
21
+ rspec-expectations (2.6.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.6.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ json_object!
30
+ rspec
@@ -0,0 +1,19 @@
1
+ # JSONObject
2
+
3
+ * http://github.com/sprysoft/json_object
4
+
5
+ ## Description
6
+
7
+ JSONObject is a simple Ruby library for converting JSON objects into Ruby classes.
8
+
9
+ It:
10
+ 1. Simplifies parsing JSON objects into classes
11
+ 2. Creates a series of setters, getters with instance variables for your new classes
12
+
13
+ ## An Introduction
14
+
15
+ ### Installation
16
+
17
+ Installation could be simpler but lets be honest it's not difficult
18
+
19
+ gem 'json_object', :git => "git@github.com:sprysoft/json_object.git"
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :spec do
4
+ system "rspec -c spec"
5
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "json_object/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "json_object"
7
+ s.version = JSONObject::VERSION
8
+ s.authors = ["David White"]
9
+ s.email = ["david@spry-soft.com"]
10
+ s.homepage = "http://www.spry-soft.com"
11
+ s.summary = "A simple Ruby library for converting JSON objects into Ruby classes."
12
+ s.description = "A simple Ruby library for converting JSON objects into Ruby classes."
13
+
14
+ s.rubyforge_project = "json_object"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "json"
24
+ s.add_runtime_dependency "activesupport"
25
+ s.add_runtime_dependency "i18n"
26
+ end
@@ -0,0 +1,28 @@
1
+ require "json_object/version"
2
+ require "json"
3
+ require "active_support/core_ext/string"
4
+
5
+ module JSONObject
6
+ def self.json_to_object json = "", class_name = "object"
7
+ klass = class_name == "object" ? Object.new : class_name.constantize.classify.new
8
+
9
+ unless json == ""
10
+ json_obj = JSON.parse(json)
11
+
12
+ klass.class_eval do
13
+ attr_accessor *(json_obj.keys)
14
+
15
+ define_method :initialize do |*values|
16
+ names.each_with_index do |name,i|
17
+ instance_variable_set("@"+name, values[i])
18
+ end
19
+ end
20
+ end
21
+
22
+ json_obj.each do |key, value|
23
+ klass.instance_variable_set "@#{key}".to_sym, value
24
+ end
25
+ end
26
+ return klass
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module JSONObject
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ require 'json_object'
2
+
3
+ describe JSONObject do
4
+ context '#json_to_object' do
5
+ it 'should return Object class when no json is passed' do
6
+ object = JSONObject.json_to_object
7
+ object.class.should == Object.new.class
8
+ end
9
+
10
+ context ' created with following JSON "{ "name" : "David" }"' do
11
+
12
+ before :all do
13
+ json = '{ "name" : "David" }'
14
+ @object = JSONObject.json_to_object json
15
+ puts @object.inspect
16
+ end
17
+
18
+ it 'should return Object class that responds to name method' do
19
+ @object.respond_to?(:name).should == true
20
+ end
21
+
22
+ it 'should return Object class that returns "David" on name method' do
23
+ @object.name.should == "David"
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ $LOAD_PATH << File.expand_path(File.join('..', 'lib'), File.dirname(__FILE__))
4
+
5
+ RSpec.configure do |c|
6
+ c.filter_run :focus => true
7
+ c.run_all_when_everything_filtered = true
8
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: json_object
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - David White
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-28 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: activesupport
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: i18n
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ description: A simple Ruby library for converting JSON objects into Ruby classes.
61
+ email:
62
+ - david@spry-soft.com
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files: []
68
+
69
+ files:
70
+ - .gitignore
71
+ - .rvmrc
72
+ - Gemfile
73
+ - Gemfile.lock
74
+ - README.markdown
75
+ - Rakefile
76
+ - json_object.gemspec
77
+ - lib/json_object.rb
78
+ - lib/json_object/version.rb
79
+ - spec/json_object_spec.rb
80
+ - spec/spec_helper.rb
81
+ has_rdoc: true
82
+ homepage: http://www.spry-soft.com
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
102
+ requirements: []
103
+
104
+ rubyforge_project: json_object
105
+ rubygems_version: 1.5.0
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A simple Ruby library for converting JSON objects into Ruby classes.
109
+ test_files:
110
+ - spec/json_object_spec.rb
111
+ - spec/spec_helper.rb