NortonAntiVirus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in NortonAntiVirus.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Valentin Tsatskin
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.
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'NortonAntiVirus/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "NortonAntiVirus"
8
+ gem.version = NortonAntiVirus::VERSION
9
+ gem.authors = ["Valentin Tsatskin"]
10
+ gem.email = ["val@valtsatskin.com"]
11
+ gem.description = %q{Helps protect against the most sofisticated internet organized crime.}
12
+ gem.summary = %q{Extends your models with filtering for creating, updating, and showing your lovely data.}
13
+ gem.homepage = "http://github.com/vtsatskin/NortonAntiVirus"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # NortonAntiVirus
2
+ Extends your [MongoMapper][] and [DataMapper][] models with filtering for creating, updating, and showing your lovely data. Helps protect against the most sofisticated internet organized crime.
3
+
4
+ ## Installation
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'NortonAntiVirus'
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install NortonAntiVirus
16
+
17
+ ## Usage
18
+ ### In your models...
19
+
20
+ require 'NortonAntiVirus'
21
+
22
+ class User
23
+ include DataMapper::Resource
24
+ include NortonAntiVirus
25
+
26
+ PUBLIC_CREATEABLE_KEYS = :name, :email, :password
27
+ PUBLIC_UPDATABLE_KEYS = :name, :email, :password
28
+ PUBLIC_KEYS = :id, :name, :email
29
+
30
+ property :id, Serial
31
+ property :name, String
32
+ property :email, String
33
+ property :admin, Boolean
34
+ property :password, String
35
+ property :super_secret_data, String
36
+ end
37
+
38
+ ### In your controllers...
39
+
40
+ # params is data supplied by a (malicious) user
41
+ # params =>
42
+ # [ :id => 20,
43
+ # :name => "John Doe",
44
+ # :email => "some@email.com",
45
+ # :password => "password123",
46
+ # :admin => true,
47
+ # :'Im-a-hacker' => true ]
48
+
49
+ post '/new_user' do
50
+ # Only :name, :email, and :password get passed into our model's create method
51
+ user = User.create_from_public_hash(params)
52
+
53
+ # Only data we want to expose publicly will appear: :id, :name, :email
54
+ user.to_public_json
55
+ # => "{\"id\":\"1\",\"name\":\"John Doe\",\"email\":\"some@email.com\"}"
56
+ end
57
+
58
+ ### Requirements
59
+ Whatever model you do choose to protect, ensure it supports the following methods:
60
+
61
+ * `::create`
62
+ * `.save`
63
+ * `.update_attributes`
64
+ * `.<attr>=`
65
+ * `.to_json`
66
+
67
+ ## Availible Methods
68
+ * `Model.create_from_public_json(json_params)`
69
+ * `Model.create_from_public(hashed_params)`
70
+ * `Model.update_properties_from_public_json(json_params)`
71
+ * `Model.update_properties_from_public_hash(hashed_params)`
72
+ * `Model.to_public_json`
73
+ * `Model.to_public_hash`
74
+
75
+ ## Contributing
76
+
77
+ 1. Fork it
78
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
79
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
80
+ 4. Push to the branch (`git push origin my-new-feature`)
81
+ 5. Create new Pull Request
82
+
83
+ [MongoMapper]: http://mongomapper.com/
84
+ [DataMapper]: http://datamapper.org/
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module NortonAntiVirus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,65 @@
1
+ require "NortonAntiVirus/version"
2
+ require 'json'
3
+
4
+ # Set these constants in your parent class
5
+ # PUBLIC_CREATEABLE_KEYS = []
6
+ # PUBLIC_UPDATABLE_KEYS = []
7
+ # PUBLIC_KEYS = []
8
+
9
+ module NortonAntiVirus
10
+
11
+ def self.included(base)
12
+ base.extend(ClassMethods)
13
+ end
14
+
15
+ module ClassMethods
16
+ # Creates an object from properties whitelisted in PUBLIC_CREATEABLE_KEYS from a given JSON string
17
+ def create_from_public_json virus = String.new
18
+ create_from_public_hash(JSON.parse(virus))
19
+ end
20
+
21
+ # Creates object from properties whitelisted in PUBLIC_CREATEABLE_KEYS
22
+ def create_from_public_hash virus = {}
23
+ filtered_params = {}
24
+ self::PUBLIC_CREATEABLE_KEYS.each do |good_key|
25
+ filtered_params[good_key] = virus[good_key]
26
+ end
27
+
28
+ # This method must be present in the parent Class
29
+ self.create(filtered_params)
30
+ end
31
+ end
32
+
33
+ # Updates self w/ filtered properties whitelisted in PUBLIC_UPDATABLE_KEYS from a given JSON string
34
+ def update_properties_from_public_json virus = String.new
35
+ update_properties_from_public_hash(JSON.parse(virus))
36
+ end
37
+
38
+ # Updates self w/ filtered properties whitelisted in PUBLIC_UPDATABLE_KEYS
39
+ def update_properties_from_public_hash virus = {}
40
+ filtered_params = {}
41
+ self.class::PUBLIC_UPDATABLE_KEYS.each do |good_key|
42
+ filtered_params[good_key] = virus[good_key]
43
+ end
44
+
45
+ unless filtered_params.empty?
46
+ self.update_attributes filtered_params
47
+ self.save
48
+ end
49
+
50
+ self
51
+ end
52
+
53
+ # Returns self w/ filtered properties whitelisted in PUBLIC_KEYS
54
+ # formatted as JSON string
55
+ def to_public_json
56
+ self.to_public_hash.to_json
57
+ end
58
+
59
+ # Returns self w/ filtered properties whitelisted in PUBLIC_KEYS
60
+ def to_public_hash
61
+ hash = {}
62
+ self.class::PUBLIC_KEYS.each { |key| hash[key] = self.send(key) }
63
+ hash
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: NortonAntiVirus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Valentin Tsatskin
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Helps protect against the most sofisticated internet organized crime.
15
+ email:
16
+ - val@valtsatskin.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - NortonAntiVirus.gemspec
25
+ - README.md
26
+ - Rakefile
27
+ - lib/NortonAntiVirus.rb
28
+ - lib/NortonAntiVirus/version.rb
29
+ homepage: http://github.com/vtsatskin/NortonAntiVirus
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: Extends your models with filtering for creating, updating, and showing your
53
+ lovely data.
54
+ test_files: []