thrivesmart-xml_protected 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/LICENSE +20 -0
  2. data/README.textile +83 -0
  3. data/Rakefile +73 -0
  4. data/lib/xml_protected.rb +35 -0
  5. metadata +57 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 [name of plugin creator]
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.textile ADDED
@@ -0,0 +1,83 @@
1
+ h1. XmlProtected
2
+
3
+ Keeps specified attributes of a model out of to_xml, by aliasing to_xml, and automatically sending in the correct <code>:excludes</code> to the original <code>to_xml</code> method, e.g. <code>:excludes => [:attr1, :attr2, ...]</code>
4
+
5
+ NOTE: as of this time, it doesn't protect these attributes from reading. For that, use this in conjunction with <code>:attr_protected</code>
6
+
7
+
8
+ h2. Usage
9
+
10
+ An ActiveRecord Model:
11
+
12
+ <pre>
13
+ class Model < ActiveRecord::Base
14
+ include XmlProtected # Required because it's a gemmefied plugin
15
+ xml_protected :attr1, :attr2, :attr3
16
+ end
17
+ </pre>
18
+
19
+ You can also access these attributes from the added class method:
20
+
21
+ <code>protected_xml_attributes</code>
22
+
23
+ h3. In Conjunction with <code>attr_protected</code>
24
+
25
+
26
+ <pre>
27
+ class Model < ActiveRecord::Base
28
+ include XmlProtected # Required because it's a gemmefied plugin
29
+ attr_protected :attr1, :attr2, :attr3
30
+ xml_protected :attr1, :attr2, :attr3
31
+ end
32
+ </pre>
33
+
34
+ h2. Installation
35
+
36
+ To enable the library your Rails 2.1 (or greater) project, use the gem configuration method in "<code>config/environment.rb</code>"
37
+
38
+ <pre>
39
+ Rails::Initializer.run do |config|
40
+ config.gem 'thrivesmart-xml_protected', :lib => 'xml_protected', :source => 'http://gems.github.com'
41
+ end
42
+ </pre>
43
+
44
+ The <code>:lib</code> is important, because rails gets confused when the name of the gem is different from the library.
45
+
46
+ And of course, run
47
+
48
+ <pre>
49
+ rake gems:install
50
+ </pre>
51
+
52
+ To get them installed on your system.
53
+
54
+ Optionally, to unpack it into your application, just run:
55
+
56
+ <pre>
57
+ rake gems:unpack GEM=thrivesmart-xml_protected
58
+ </pre>
59
+
60
+
61
+ h2. How it works
62
+
63
+ Two methods are extended onto your active record class:
64
+
65
+ 1. <code>xml_protected(*attributes)</code>
66
+ 2. <code>protected_xml_attributes</code>
67
+
68
+ 1. Adds to the inheritable attribute "xml_protected_attrs" the attributes that are speicified in this call. If this is the first time the method is called, it also aliases the old to_xml, and specified a new one which reads from these xml_protected_attrs
69
+
70
+ 2. Simply returns the values currently in "xml_protected_attrs".
71
+
72
+ One method is included into your active record class, which is pretty self explanatory:
73
+
74
+ <pre>
75
+ def to_xml(options = {})
76
+ options[:except] ||= []
77
+ xml_protected_to_xml(options.merge(:except => options[:except].concat(self.class.protected_xml_attributes)))
78
+ end
79
+ </pre>
80
+
81
+ h2. Copyright & License
82
+
83
+ Copyright (c) 2008 ThriveSmart, LLC, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/rdoctask'
4
+ require 'rubygems/specification'
5
+ # require 'spec/rake/spectask'
6
+ require 'date'
7
+
8
+ GEM = "xml_protected"
9
+ HUMANIZED_GEM = "XmlProtected"
10
+ GEM_VERSION = "0.0.5"
11
+ AUTHOR = "ThriveSmart, LLC"
12
+ EMAIL = "developers@thrivesmart.com"
13
+ HOMEPAGE = "http://www.github.com/thrivesmart/xml_protected"
14
+ SUMMARY = "Keeps specified attributes of a model out of to_xml. Do so by aliasing to_xml, and automatically sending in the correct :excludes to the original to_xml method, e.g. :excludes => [:attr1, :attr2, ...]"
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.name = GEM
18
+ s.version = GEM_VERSION
19
+ s.platform = Gem::Platform::RUBY
20
+ s.rubyforge_project = GEM
21
+ s.has_rdoc = true
22
+ s.extra_rdoc_files = ['README.textile', 'LICENSE']
23
+ s.summary = SUMMARY
24
+ s.description = s.summary
25
+ s.author = AUTHOR
26
+ s.email = EMAIL
27
+ s.homepage = HOMEPAGE
28
+
29
+ # Uncomment this to add a dependency
30
+ # s.add_dependency "foo"
31
+
32
+ s.require_path = 'lib'
33
+ s.files = %w(LICENSE README.textile Rakefile) + Dir.glob("{lib,spec}/**/*")
34
+ end
35
+
36
+ desc "Run Specs"
37
+ Rake::GemPackageTask.new(spec) do |pkg|
38
+ pkg.gem_spec = spec
39
+ end
40
+
41
+ desc "Generate Documentation"
42
+ Rake::RDocTask.new do |rdoc|
43
+ rdoc.rdoc_dir = 'doc'
44
+ rdoc.title = HUMANIZED_GEM
45
+ rdoc.options << '--line-numbers' << '--inline-source' << '--main' << HUMANIZED_GEM
46
+ rdoc.rdoc_files.include(FileList[ 'lib/**/*.rb', 'README.textile', 'LICENSE'])
47
+ end
48
+
49
+ task :default => :spec
50
+ task :specs => :spec
51
+
52
+ # desc "Run all examples"
53
+ # Spec::Rake::SpecTask.new('spec') do |t|
54
+ # t.spec_opts = ['--options','spec/spec.opts']
55
+ # t.spec_files = FileList['spec/**/*.rb']
56
+ # t.rcov = true
57
+ # end
58
+
59
+ desc "install the gem locally"
60
+ task :install => [:package] do
61
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
62
+ end
63
+
64
+ desc "create a gemspec file"
65
+ task :make_spec do
66
+ File.open("#{GEM}.gemspec", "w") do |file|
67
+ file.puts spec.to_ruby
68
+ end
69
+ end
70
+
71
+ task :bugs do
72
+ sh %{ditz html ; open html/index.html}
73
+ end
@@ -0,0 +1,35 @@
1
+ # Usage: xml_protected :attr1, :attr2, :attr3
2
+ module XmlProtected
3
+
4
+ def self.included(klass)
5
+ klass.extend ActMethods
6
+ end
7
+
8
+ module ActMethods
9
+
10
+ def xml_protected(*attributes)
11
+ write_inheritable_attribute("xml_protected_attrs", Set.new(attributes.map(&:to_s)) + (protected_xml_attributes || []))
12
+
13
+ # only need to define these once on a class
14
+ unless included_modules.include?(InstanceMethods)
15
+ alias_method :xml_protected_to_xml, :to_xml
16
+ include InstanceMethods
17
+ end
18
+ end
19
+
20
+ # Returns an array of all the attributes that have been protected (excluded) from default to_xml output.
21
+ def protected_xml_attributes # :nodoc:
22
+ read_inheritable_attribute("xml_protected_attrs")
23
+ end
24
+
25
+ end
26
+
27
+ module InstanceMethods
28
+ def to_xml(options = {})
29
+ xml_protected_to_xml(
30
+ options.merge(
31
+ :except => self.class.protected_xml_attributes + (options[:except] || [])
32
+ ))
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thrivesmart-xml_protected
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - ThriveSmart, LLC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-01 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Keeps specified attributes of a model out of to_xml. Do so by aliasing to_xml, and automatically sending in the correct :excludes to the original to_xml method, e.g. :excludes => [:attr1, :attr2, ...]
17
+ email: developers@thrivesmart.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.textile
24
+ - LICENSE
25
+ files:
26
+ - LICENSE
27
+ - README.textile
28
+ - Rakefile
29
+ - lib/xml_protected.rb
30
+ has_rdoc: true
31
+ homepage: http://www.github.com/thrivesmart/xml_protected
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project: xml_protected
52
+ rubygems_version: 1.2.0
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Keeps specified attributes of a model out of to_xml. Do so by aliasing to_xml, and automatically sending in the correct :excludes to the original to_xml method, e.g. :excludes => [:attr1, :attr2, ...]
56
+ test_files: []
57
+