deas-json 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61ae5145b44df2f3936dcf70381fe6385a4ee5df
4
+ data.tar.gz: 1490ab77c5cafdc5f38c1f40cc11700b7c78e2ad
5
+ SHA512:
6
+ metadata.gz: df4da1f716409cb2ed13c095d088c0de7f080da51b2ae29d4a368ce705fa9f3e75c15bd3c02bffc557f88525d5fa67361e7ca44206f214b0469e712c7c0e859e
7
+ data.tar.gz: 5462a69cfbbf3e42d502b6655b5665dc0b51ca5e74b033e3936cd97e5d26981280a242a5cc267cc8bff1d3737c2d62371a1d5fa84ed8d479215b187daa68d8a4
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.log
3
+ *.rbc
4
+ .rbx/
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rake', "~> 10.4.0"
6
+ gem 'pry', "~> 0.9.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015-Present Kelly Redding and Collin Redding
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Deas::Json
2
+
3
+ JSON helpers for [Deas](https://github.com/redding/deas) apps.
4
+
5
+ ## Usage
6
+
7
+ TODO: Write code samples and usage instructions here
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'deas-json'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install deas-json
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/deas-json.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "deas-json/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "deas-json"
8
+ gem.version = Deas::Json::VERSION
9
+ gem.authors = ["Kelly Redding", "Collin Redding"]
10
+ gem.email = ["kelly@kellyredding.com", "collin.redding@me.com"]
11
+ gem.description = %q{JSON helpers for Deas apps}
12
+ gem.summary = %q{JSON helpers for Deas apps}
13
+ gem.homepage = "http://github.com/redding/deas-json"
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency("assert", ["~> 2.14"])
22
+
23
+ gem.add_dependency("deas", ["~> 0.34"])
24
+
25
+ end
@@ -0,0 +1,4 @@
1
+ module Deas; end
2
+ module Deas::Json
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,34 @@
1
+ require 'deas/view_handler'
2
+
3
+ module Deas::Json
4
+
5
+ module ViewHandler
6
+
7
+ def self.included(klass)
8
+ klass.class_eval do
9
+ include Deas::ViewHandler
10
+ include InstanceMethods
11
+ end
12
+ end
13
+
14
+ module InstanceMethods
15
+
16
+ def initialize(*args)
17
+ super(*args)
18
+ content_type :json
19
+ end
20
+
21
+ private
22
+
23
+ # Some http clients will error when trying to parse an empty body when the
24
+ # content type is 'json'. This will default the body to a string that
25
+ # can be parsed to an empty json object
26
+ def halt(status, headers = {}, body = '{}')
27
+ super(status, headers, body)
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+ end
data/lib/deas-json.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "deas-json/version"
2
+ require 'deas-json/view_handler'
3
+
4
+ module Deas::Json; end
data/log/.gitkeep ADDED
File without changes
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ # this file is automatically required when you run `assert`
2
+ # put any test helpers here
3
+
4
+ # add the root dir to the load path
5
+ $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
6
+
7
+ # require pry for debugging (`binding.pry`)
8
+ require 'pry'
9
+
10
+ require 'test/support/factory'
@@ -0,0 +1,6 @@
1
+ require 'assert/factory'
2
+
3
+ module Factory
4
+ extend Assert::Factory
5
+
6
+ end
@@ -0,0 +1,70 @@
1
+ require 'assert'
2
+ require 'deas-json/view_handler'
3
+
4
+ require 'deas/test_helpers'
5
+ require 'deas/view_handler'
6
+
7
+ module Deas::Json::ViewHandler
8
+
9
+ class UnitTests < Assert::Context
10
+ desc "Deas::Json::ViewHandler"
11
+ setup do
12
+ @handler_class = TestJsonHandler
13
+ end
14
+ subject{ @handler_class }
15
+
16
+ should "be a deas view handler" do
17
+ assert_includes Deas::ViewHandler, subject
18
+ end
19
+
20
+ end
21
+
22
+ class InitTests < UnitTests
23
+ include Deas::TestHelpers
24
+
25
+ desc "when init"
26
+ setup do
27
+ @runner = test_runner(@handler_class)
28
+ @handler = @runner.handler
29
+ end
30
+ subject{ @runner }
31
+
32
+ should "force its content type to :json" do
33
+ assert_equal :json, subject.content_type.value
34
+ end
35
+
36
+ should "default its body and headers if not provided" do
37
+ @handler.status = Factory.integer
38
+ response = @runner.run
39
+
40
+ assert_equal @handler.status, response.status
41
+ assert_equal({}, response.headers)
42
+ assert_equal '{}', response.body
43
+ end
44
+
45
+ should "allow halting with a body and headers" do
46
+ @handler.status = Factory.integer
47
+ @handler.headers = { Factory.string => Factory.string }
48
+ @handler.body = Factory.text
49
+ response = @runner.run
50
+
51
+ assert_equal @handler.status, response.status
52
+ assert_equal @handler.headers, response.headers
53
+ assert_equal @handler.body, response.body
54
+ end
55
+
56
+ end
57
+
58
+ class TestJsonHandler
59
+ include Deas::Json::ViewHandler
60
+
61
+ attr_accessor :status, :headers, :body
62
+
63
+ def run!
64
+ args = [status, headers, body].compact
65
+ halt *args
66
+ end
67
+
68
+ end
69
+
70
+ end
data/tmp/.gitkeep ADDED
File without changes
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deas-json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kelly Redding
8
+ - Collin Redding
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-06-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: assert
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '2.14'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '2.14'
28
+ - !ruby/object:Gem::Dependency
29
+ name: deas
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.34'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.34'
42
+ description: JSON helpers for Deas apps
43
+ email:
44
+ - kelly@kellyredding.com
45
+ - collin.redding@me.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - deas-json.gemspec
56
+ - lib/deas-json.rb
57
+ - lib/deas-json/version.rb
58
+ - lib/deas-json/view_handler.rb
59
+ - log/.gitkeep
60
+ - test/helper.rb
61
+ - test/support/factory.rb
62
+ - test/unit/view_handler_tests.rb
63
+ - tmp/.gitkeep
64
+ homepage: http://github.com/redding/deas-json
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.4.5
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: JSON helpers for Deas apps
88
+ test_files:
89
+ - test/helper.rb
90
+ - test/support/factory.rb
91
+ - test/unit/view_handler_tests.rb