hide_attributes 0.1.4
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/MIT-LICENSE +20 -0
- data/README +50 -0
- data/Rakefile +40 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/hide_attributes.rb +40 -0
- data/rails/init.rb +2 -0
- data/uninstall.rb +1 -0
- metadata +85 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Laas Toom
|
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.
|
data/README
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
= HideAttributes
|
2
|
+
|
3
|
+
This plugin generates wrappers to `to_xml` and `to_json` methods to
|
4
|
+
automatically exclude attributes such as passwords from output.
|
5
|
+
|
6
|
+
|
7
|
+
== Example
|
8
|
+
|
9
|
+
To auto-hide password fields from generated JSON output, add this to your model:
|
10
|
+
|
11
|
+
class User < ActiveRecord::Base
|
12
|
+
|
13
|
+
hide_attributes :password, :password_salt
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
Then use as usual:
|
19
|
+
|
20
|
+
user = User.first
|
21
|
+
|
22
|
+
# Output user's JSON without hidden attributes present
|
23
|
+
user.to_json
|
24
|
+
|
25
|
+
# Temporarly override hiding and output all attributes
|
26
|
+
user.to_json :except => nil
|
27
|
+
|
28
|
+
|
29
|
+
== INSTALL
|
30
|
+
|
31
|
+
To install simply add it to your _Gemfile_
|
32
|
+
|
33
|
+
gem 'hide_attributes'
|
34
|
+
|
35
|
+
And run bundle:
|
36
|
+
|
37
|
+
bundle install
|
38
|
+
|
39
|
+
|
40
|
+
== Requirements
|
41
|
+
|
42
|
+
Runtime requirements are:
|
43
|
+
|
44
|
+
* ActiveRecord >=3.0
|
45
|
+
|
46
|
+
== TODO
|
47
|
+
|
48
|
+
* Write tests
|
49
|
+
|
50
|
+
Copyright (c) 2011 Laas Toom, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the hide_attributes plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the hide_attributes plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'HideAttributes'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
24
|
+
|
25
|
+
begin
|
26
|
+
require 'jeweler'
|
27
|
+
Jeweler::Tasks.new do |gemspec|
|
28
|
+
gemspec.name = "hide_attributes"
|
29
|
+
gemspec.summary = "ActiveRecord to JSON or XML without sensitive data"
|
30
|
+
gemspec.description = "Autohides sensitive attributes (such as passwords) when rendering XML or JSON from ActiveRecord model"
|
31
|
+
gemspec.email = "laas.toom@gmail.com"
|
32
|
+
gemspec.homepage = "http://github.com/borgand/hide_attributes"
|
33
|
+
gemspec.authors = ["Laas Toom"]
|
34
|
+
|
35
|
+
gemspec.add_runtime_dependency("activerecord", ">= 3.0")
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
39
|
+
end
|
40
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.4
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'rails', 'init')
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module HideAttributes #:nodoc:
|
2
|
+
module ClassMethods
|
3
|
+
|
4
|
+
# Macro to specify which attributes are to be hidden
|
5
|
+
#
|
6
|
+
# hide_attributes :password, :password_salt
|
7
|
+
def hide_attributes(*arr)
|
8
|
+
@hidden_attributes = arr.flatten
|
9
|
+
end
|
10
|
+
attr_reader :hidden_attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
# Merge +to_xml+ options with +:exclude => hidden_attributes+
|
14
|
+
def to_xml_with_hidden(opts=nil, &block)
|
15
|
+
merge_options_and_call(:to_xml_without_hidden, opts, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Merge +as_json+ with +:exclude => hidden_attributes+
|
19
|
+
def to_json_with_hidden(opts=nil)
|
20
|
+
merge_options_and_call(:to_json_without_hidden, opts)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Hook up class methods and aliases
|
24
|
+
def self.included(base)
|
25
|
+
base.extend(ClassMethods)
|
26
|
+
base.alias_method_chain :to_xml, :hidden
|
27
|
+
base.alias_method_chain :to_json, :hidden
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
# Merge options with +:exclude => hidden_attributes+ and call indicated formatter
|
32
|
+
def merge_options_and_call(formatter, opts=nil, &block)
|
33
|
+
opts ||= {}
|
34
|
+
send(formatter, {:except => self.class.hidden_attributes}.merge(opts), &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
ActiveRecord::Base.send :include, HideAttributes
|
40
|
+
|
data/rails/init.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hide_attributes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Laas Toom
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-17 00:00:00 +03:00
|
18
|
+
default_executable:
|
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
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 0
|
31
|
+
version: "3.0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
description: Autohides sensitive attributes (such as passwords) when rendering XML or JSON from ActiveRecord model
|
35
|
+
email: laas.toom@gmail.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- README
|
42
|
+
files:
|
43
|
+
- MIT-LICENSE
|
44
|
+
- README
|
45
|
+
- Rakefile
|
46
|
+
- VERSION
|
47
|
+
- init.rb
|
48
|
+
- install.rb
|
49
|
+
- lib/hide_attributes.rb
|
50
|
+
- rails/init.rb
|
51
|
+
- uninstall.rb
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://github.com/borgand/hide_attributes
|
54
|
+
licenses: []
|
55
|
+
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
segments:
|
67
|
+
- 0
|
68
|
+
version: "0"
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.3.7
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: ActiveRecord to JSON or XML without sensitive data
|
84
|
+
test_files: []
|
85
|
+
|