json-response 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.
- data/.gitignore +17 -0
- data/README.md +21 -0
- data/Rakefile +2 -0
- data/json-response.gemspec +18 -0
- data/lib/json_response.rb +25 -0
- data/spec/json_response_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -0
- metadata +65 -0
data/.gitignore
ADDED
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# JSONResponse
|
2
|
+
|
3
|
+
Define JSON responses, factory style!
|
4
|
+
|
5
|
+
JSONResponse.define :character do |p|
|
6
|
+
p.name = "Finn"
|
7
|
+
p.age = 13
|
8
|
+
p.type = "human"
|
9
|
+
end
|
10
|
+
|
11
|
+
Use those responses to do stuff!
|
12
|
+
|
13
|
+
JSONResponse.build(:character)
|
14
|
+
# => "{\"name\":\"Finn",\"age\":13,\"type\":\"human\"}"
|
15
|
+
|
16
|
+
Overwrite default values!
|
17
|
+
|
18
|
+
JSONResponse.build(:character, name: "Jake", age: 48, type: "dog")
|
19
|
+
# => "{\"name\":\"Jake",\"age\":48,\"type\":\"dog\"}"
|
20
|
+
|
21
|
+
MATHEMATICAL!
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/json_response', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Matte Noble"]
|
6
|
+
gem.email = ["me@mattenoble.com"]
|
7
|
+
gem.description = %q{Define factories to be built as JSON.}
|
8
|
+
gem.summary = %q{Define factories to be built as JSON.}
|
9
|
+
|
10
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
|
+
gem.name = "json-response"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = JSONResponse::VERSION
|
16
|
+
|
17
|
+
gem.add_development_dependency "rspec", "~> 2.6.0"
|
18
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "ostruct"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module JSONResponse
|
5
|
+
VERSION = "0.0.1"
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def define(name)
|
9
|
+
yield (registry[name] = OpenStruct.new)
|
10
|
+
end
|
11
|
+
|
12
|
+
def build(name, options={})
|
13
|
+
JSON.generate(registry[name].marshal_dump.merge(options))
|
14
|
+
end
|
15
|
+
|
16
|
+
def attributes_for(name, options={})
|
17
|
+
registry[name].marshal_dump.merge(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def registry
|
23
|
+
@registry ||= {}
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe JSONResponse, ".build" do
|
4
|
+
before do
|
5
|
+
JSONResponse.define(:person) { |p| p.name = "Dave" }
|
6
|
+
end
|
7
|
+
|
8
|
+
it "builds json strings from definitions" do
|
9
|
+
JSONResponse.build(:person).should == "{\"name\":\"Dave\"}"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "builds a hash of attributes from definitions" do
|
13
|
+
JSONResponse.attributes_for(:person).should == {name: "Dave"}
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../lib/json_response"
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: json-response
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matte Noble
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-08-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &2152529240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.6.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152529240
|
25
|
+
description: Define factories to be built as JSON.
|
26
|
+
email:
|
27
|
+
- me@mattenoble.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- README.md
|
34
|
+
- Rakefile
|
35
|
+
- json-response.gemspec
|
36
|
+
- lib/json_response.rb
|
37
|
+
- spec/json_response_spec.rb
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
homepage:
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ! '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.8.7
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Define factories to be built as JSON.
|
63
|
+
test_files:
|
64
|
+
- spec/json_response_spec.rb
|
65
|
+
- spec/spec_helper.rb
|