unveil 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ unveil (0.1.5)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ activemodel (3.2.11)
10
+ activesupport (= 3.2.11)
11
+ builder (~> 3.0.0)
12
+ activerecord (3.2.11)
13
+ activemodel (= 3.2.11)
14
+ activesupport (= 3.2.11)
15
+ arel (~> 3.0.2)
16
+ tzinfo (~> 0.3.29)
17
+ activesupport (3.2.11)
18
+ i18n (~> 0.6)
19
+ multi_json (~> 1.0)
20
+ arel (3.0.2)
21
+ builder (3.0.4)
22
+ i18n (0.6.1)
23
+ multi_json (1.6.0)
24
+ rake (10.0.3)
25
+ sqlite3 (1.3.7)
26
+ tzinfo (0.3.35)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ activerecord
33
+ bundler
34
+ rake
35
+ sqlite3
36
+ unveil!
data/HISTORY.md ADDED
@@ -0,0 +1,24 @@
1
+ History
2
+ =======
3
+
4
+ 0.1.5 - February 22, 2013
5
+ -------------------------
6
+ + Modernize the gem by adding Bundler and using modern gem conventions
7
+ + Add Travis CI
8
+
9
+ 0.1.4 - February 15, 2011
10
+ -------------------------
11
+ + Fix a bug where scopes are available to all models
12
+
13
+ 0.1.3 - February 15, 2011
14
+ -------------------------
15
+ + Write tests for old features
16
+ + Allow named scopes (e.g. @post.unveil(:with_comments))
17
+ + Allow calling unveil on an object even if unveil wasn't called in the model
18
+ + Write tests for new features
19
+ + Document the installation process in the README
20
+ + Document the :include option in the README
21
+
22
+ 0.1.2 - January 13, 2011
23
+ ------------------------
24
+ This was the first real version, so it introduced the basic functionality.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Shaun Chapman
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,174 @@
1
+ Unveil
2
+ ======
3
+ [![Build Status](https://travis-ci.org/shaunchapman/unveil.png?branch=master)](https://travis-ci.org/shaunchapman/unveil)
4
+
5
+ Unveil provides a super simple way to specify which of a model's attributes are available to an API in a Ruby on Rails application.
6
+
7
+
8
+ Usage
9
+ -----
10
+ The basic usage is as follows:
11
+
12
+ 1. In your model, specify which attributes should be available to the API:
13
+
14
+ class User < ActiveRecord::Base
15
+ unveil :only => [:id, :first_name, :last_name, :email], :methods => :name
16
+
17
+ def name
18
+ "#{first_name} #{last_name}"
19
+ end
20
+ end
21
+
22
+ 2. In your controller, call `unveil`:
23
+
24
+ class UsersController < ApplicationController
25
+ def index
26
+ @users = User.all
27
+
28
+ respond_to do |format|
29
+ format.html
30
+ format.json { render :json => @users.unveil }
31
+ format.xml { render :xml => @users.unveil }
32
+ end
33
+ end
34
+
35
+ def show
36
+ @user = User.find(params[:id])
37
+
38
+ respond_to do |format|
39
+ format.html
40
+ format.json { render :json => @user.unveil }
41
+ format.xml { render :xml => @user.unveil }
42
+ end
43
+ end
44
+ end
45
+
46
+
47
+ ### Create named scopes
48
+
49
+ This following will create a named scope `:authenticated` in addition to the default scope:
50
+
51
+ class User < ActiveRecord::Base
52
+ unveil :only => [:id, :first_name, :last_name]
53
+ unveil :authenticated
54
+ end
55
+
56
+ Example:
57
+
58
+ >> User.first.unveil
59
+ => {"id" => 1, "first_name" => "John", "last_name" => "Smith"}
60
+ >> User.first.unveil(:authenticated)
61
+ => {"id" => 1, "first_name" => "John", "last_name" => "Smith", :email => "johnsmith@example.com"}
62
+
63
+
64
+ ### Include associated records
65
+
66
+ class Post < ActiveRecord::Base
67
+ unveil :only => [:id, :title, :body]
68
+
69
+ unveil :with_comments,
70
+ :only => [:id, :title, :body],
71
+ :include => {
72
+ :comments => {
73
+ :except => :user_id,
74
+ :include => {
75
+ :user => {
76
+ :only => [:id, :username],
77
+ :methods => [:name, :picture_url]
78
+ }
79
+ }
80
+ }
81
+ }
82
+ end
83
+
84
+ Calling `Post.all.unveil(:with_comments)` might return something like:
85
+
86
+ [
87
+ {
88
+ "id" => 1,
89
+ "title" => "Best Post Ever",
90
+ "body" => "This is the post.",
91
+ "comments" => [
92
+ {
93
+ "id": 1,
94
+ "body": "First comment",
95
+ "user": {
96
+ "id": 3,
97
+ "username": "forrestgump",
98
+ "name": "Forrest Gump",
99
+ "picture_url": "http://example.com/images/user_pictures/3.jpg"
100
+ }
101
+ },
102
+ {
103
+ "id": 2,
104
+ "body": "Second comment",
105
+ "user": {
106
+ "id": 1,
107
+ "username": "johnsmith",
108
+ "name": "John Smith",
109
+ "picture_url": "http://example.com/images/user_pictures/1.jpg"
110
+ }
111
+ }
112
+ ]
113
+ },
114
+ {
115
+ "id" => 2,
116
+ "title" => "Second Best Post Ever",
117
+ "body" => "This is a post without comments.",
118
+ "comments" => []
119
+ }
120
+ ]
121
+
122
+
123
+ ### Override at any time
124
+
125
+ You can pass an options hash to `unveil` at any time (e.g. in a controller) if you need to fine tune what's returned for a specific object:
126
+
127
+ if @user == current_user
128
+ render :json => @user.unveil
129
+ else
130
+ render :json => @user.unveil(:except => [:birthday, :email])
131
+ end
132
+
133
+ Unveil uses [serializable_hash](http://rubydoc.info/docs/rails/ActiveModel/Serialization) so you can send any parameters to `unveil` that
134
+ `serializable_hash` accepts.
135
+
136
+
137
+ ### What's returned
138
+
139
+ + Calling `unveil` on an object will return a hash, so you can do with it anything you can do with a hash:
140
+
141
+ >> post = Post.new
142
+ => #<Post id: nil, title: nil, body: nil, views: nil, created_at: nil, updated_at: nil>
143
+ >> post.attribute_names
144
+ => ["body", "created_at", "title", "updated_at", "views"]
145
+ >> post.unveil.keys
146
+ => ["body", "title"]
147
+
148
+ + Calling `unveil` on an array of objects returns an array of hashes.
149
+
150
+
151
+ Installation
152
+ ------------
153
+ Install the gem with Bundler:
154
+
155
+ 1. Add the following to your `Gemfile`:
156
+
157
+ gem 'unveil'
158
+
159
+ 2. Run:
160
+
161
+ bundle install
162
+
163
+ Or install the gem with RubyGems:
164
+
165
+ gem install unveil
166
+
167
+ Or install as a Rails plugin:
168
+
169
+ rails plugin install git@github.com:shaunchapman/unveil.git
170
+
171
+
172
+ License
173
+ -------
174
+ Copyright (c) 2011 Shaun Chapman. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
- require 'rake'
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
- require 'rake/rdoctask'
4
5
 
5
6
  desc 'Default: run unit tests.'
6
7
  task :default => :test
@@ -12,12 +13,3 @@ Rake::TestTask.new(:test) do |t|
12
13
  t.pattern = 'test/**/*_test.rb'
13
14
  t.verbose = true
14
15
  end
15
-
16
- desc 'Generate documentation for the unveil plugin.'
17
- Rake::RDocTask.new(:rdoc) do |rdoc|
18
- rdoc.rdoc_dir = 'rdoc'
19
- rdoc.title = 'Unveil'
20
- rdoc.options << '--line-numbers' << '--inline-source'
21
- rdoc.rdoc_files.include('README')
22
- rdoc.rdoc_files.include('lib/**/*.rb')
23
- end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'unveil')
@@ -0,0 +1,3 @@
1
+ module Unveil
2
+ VERSION = '0.1.5'
3
+ end
data/test/test_helper.rb CHANGED
@@ -14,7 +14,7 @@ def load_schema
14
14
  # Create the fixtures
15
15
  fixtures = ActiveRecord::Schema.tables
16
16
  fixtures.delete('schema_migrations')
17
- Fixtures.create_fixtures(File.dirname(__FILE__) + '/fixtures', fixtures)
17
+ ActiveRecord::Fixtures.create_fixtures(File.dirname(__FILE__) + '/fixtures', fixtures)
18
18
 
19
19
  # Require Unveil
20
20
  require File.dirname(__FILE__) + '/../init'
data/unveil.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../lib/unveil/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'unveil'
5
+ gem.version = Unveil::VERSION
6
+
7
+ gem.authors = ['Shaun Chapman']
8
+ gem.email = ['shaunchapman@gmail.com']
9
+ gem.description = %q{Unveil provides a super simple way to specify which of a model's attributes are available to an API in a Ruby on Rails application.}
10
+ gem.summary = %q{Build custom objects for use in an API}
11
+ gem.homepage = 'https://github.com/shaunchapman/unveil'
12
+
13
+ # Dependencies
14
+ gem.add_development_dependency 'bundler'
15
+ gem.add_development_dependency 'activerecord'
16
+ gem.add_development_dependency 'rake'
17
+ gem.add_development_dependency 'sqlite3'
18
+
19
+ gem.files = `git ls-files`.split($\)
20
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
21
+ gem.require_paths = ['lib']
22
+ end
metadata CHANGED
@@ -1,71 +1,138 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: unveil
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 4
9
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Shaun Chapman
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-02-15 00:00:00 -05:00
18
- default_executable:
19
- dependencies: []
20
-
21
- description: Unveil provides a super simple way to specify which of a model's attributes are available to an API in a Ruby on Rails application.
22
- email: shaunchapman@gmail.com
12
+ date: 2013-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Unveil provides a super simple way to specify which of a model's attributes
79
+ are available to an API in a Ruby on Rails application.
80
+ email:
81
+ - shaunchapman@gmail.com
23
82
  executables: []
24
-
25
83
  extensions: []
26
-
27
84
  extra_rdoc_files: []
28
-
29
- files:
85
+ files:
86
+ - .gitignore
87
+ - .travis.yml
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - HISTORY.md
91
+ - LICENSE
92
+ - README.md
30
93
  - Rakefile
94
+ - init.rb
95
+ - lib/unveil.rb
31
96
  - lib/unveil/core_ext.rb
32
97
  - lib/unveil/error.rb
33
- - lib/unveil.rb
98
+ - lib/unveil/version.rb
34
99
  - test/fixtures/users.yml
35
100
  - test/schema.rb
36
101
  - test/test_helper.rb
37
102
  - test/unveil_test.rb
38
- has_rdoc: true
39
- homepage: http://github.com/shaunchapman/unveil
103
+ - unveil.gemspec
104
+ homepage: https://github.com/shaunchapman/unveil
40
105
  licenses: []
41
-
42
106
  post_install_message:
43
107
  rdoc_options: []
44
-
45
- require_paths:
108
+ require_paths:
46
109
  - lib
47
- required_ruby_version: !ruby/object:Gem::Requirement
110
+ required_ruby_version: !ruby/object:Gem::Requirement
48
111
  none: false
49
- requirements:
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- segments:
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ segments:
53
117
  - 0
54
- version: "0"
55
- required_rubygems_version: !ruby/object:Gem::Requirement
118
+ hash: -2556614104741764564
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
120
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- segments:
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ segments:
61
126
  - 0
62
- version: "0"
127
+ hash: -2556614104741764564
63
128
  requirements: []
64
-
65
- rubyforge_project: unveil
66
- rubygems_version: 1.3.7
129
+ rubyforge_project:
130
+ rubygems_version: 1.8.24
67
131
  signing_key:
68
132
  specification_version: 3
69
133
  summary: Build custom objects for use in an API
70
- test_files: []
71
-
134
+ test_files:
135
+ - test/fixtures/users.yml
136
+ - test/schema.rb
137
+ - test/test_helper.rb
138
+ - test/unveil_test.rb