as_jsonable 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.
@@ -0,0 +1,3 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ as_jsonable (0.1.0)
5
+ activerecord
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.2.6)
11
+ activesupport (= 3.2.6)
12
+ builder (~> 3.0.0)
13
+ activerecord (3.2.6)
14
+ activemodel (= 3.2.6)
15
+ activesupport (= 3.2.6)
16
+ arel (~> 3.0.2)
17
+ tzinfo (~> 0.3.29)
18
+ activesupport (3.2.6)
19
+ i18n (~> 0.6)
20
+ multi_json (~> 1.0)
21
+ arel (3.0.2)
22
+ builder (3.0.0)
23
+ diff-lcs (1.1.3)
24
+ i18n (0.6.0)
25
+ multi_json (1.3.6)
26
+ rspec (2.10.0)
27
+ rspec-core (~> 2.10.0)
28
+ rspec-expectations (~> 2.10.0)
29
+ rspec-mocks (~> 2.10.0)
30
+ rspec-core (2.10.1)
31
+ rspec-expectations (2.10.0)
32
+ diff-lcs (~> 1.1.3)
33
+ rspec-mocks (2.10.1)
34
+ tzinfo (0.3.33)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ as_jsonable!
41
+ rspec
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Naoto Takai
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ # as_jsonable
2
+
3
+ as_jsonable provides a tiny DSL to override ```as_json```.
4
+
5
+ # Usage
6
+
7
+ ```ruby
8
+ class Employee < ActiveRecord::Base
9
+ as_json only: [:fisrt_name, :last_name]
10
+ end
11
+ ```
12
+
13
+ This code equivalent to:
14
+
15
+ ```ruby
16
+ class Employee < ActiveRecord::Base
17
+ def as_json(options)
18
+ super({ only: [:fisrt_name, :last_name] }.merge(options))
19
+ end
20
+ end
21
+ ```
@@ -0,0 +1,3 @@
1
+ # -*- mode: ruby; coding; utf-8 -*-
2
+
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,17 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ # Describe your gem and declare its dependencies:
4
+ Gem::Specification.new do |s|
5
+ s.name = 'as_jsonable'
6
+ s.version = '0.1.0'
7
+ s.authors = ['Naoto Takai']
8
+ s.email = ['takai@cookpad.com']
9
+ s.homepage = 'http://github.com/takai/as_jsonable'
10
+ s.summary = 'DSL for as_json'
11
+ s.description = 'as_jsonable provides a tiny DSL to override as_json.'
12
+
13
+ s.files = `git ls-files`.split($\)
14
+
15
+ s.add_runtime_dependency 'activerecord'
16
+ s.add_development_dependency 'rspec'
17
+ end
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+
3
+ module AsJsonable
4
+ module ClassMethods
5
+ def as_json(options={})
6
+ define_method(:as_json) do |args|
7
+ args ||= {}
8
+ super(options.merge(args))
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ ActiveRecord::Base.send :extend, AsJsonable::ClassMethods
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: as_jsonable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Naoto Takai
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-07-25 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activerecord
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: as_jsonable provides a tiny DSL to override as_json.
49
+ email:
50
+ - takai@cookpad.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ files:
58
+ - .gitignore
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - MIT-LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - as_jsonable.gemspec
65
+ - lib/as_jsonable.rb
66
+ homepage: http://github.com/takai/as_jsonable
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.15
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: DSL for as_json
99
+ test_files: []
100
+
101
+ has_rdoc: