moorage-xml_protected 0.0.2

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.
Files changed (4) hide show
  1. data/README.textile +58 -0
  2. data/Rakefile +73 -0
  3. data/lib/xml_protected.rb +28 -0
  4. metadata +57 -0
data/README.textile ADDED
@@ -0,0 +1,58 @@
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
+ xml_protected :attr1, :attr2, :attr3
15
+ end
16
+ </pre>
17
+
18
+
19
+ h3. In Conjunction with <code>attr_protected</code>
20
+
21
+
22
+ <pre>
23
+ class Model < ActiveRecord::Base
24
+ attr_protected :attr1, :attr2, :attr3
25
+ xml_protected :attr1, :attr2, :attr3
26
+ end
27
+ </pre>
28
+
29
+ h2. Installation
30
+
31
+ To enable the library your Rails 2.1 (or greater) project, use the gem configuration method in "<code>config/environment.rb</code>"
32
+
33
+ <pre>
34
+ Rails::Initializer.run do |config|
35
+ config.gem 'moorage-xml_protected', :lib => 'xml_protected', :source => 'http://gems.github.com'
36
+ end
37
+ </pre>
38
+
39
+ The <code>:lib</code> is important, because rails gets confused when the name of the gem is different from the library.
40
+
41
+ And of course, run
42
+
43
+ <pre>
44
+ rake gems:install
45
+ </pre>
46
+
47
+ To get them installed on your system.
48
+
49
+ Optionally, to unpack it into your application, just run:
50
+
51
+ <pre>
52
+ rake gems:unpack GEM=moorage-xml_protected
53
+ </pre>
54
+
55
+
56
+ h2. Copyright & License
57
+
58
+ 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.2"
11
+ AUTHOR = "ThriveSmart, LLC"
12
+ EMAIL = "developers@thrivesmart.com"
13
+ HOMEPAGE = "http://www.github.com/moorage/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,28 @@
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
+ def xml_protected(*attrs)
10
+ # doing these shenanigans so that the option hash passed in is available to the outside world
11
+ class_inheritable_accessor :xml_protected_attrs
12
+ self.xml_protected_attrs = attrs
13
+
14
+ # only need to define these once on a class
15
+ unless included_modules.include?(InstanceMethods)
16
+ alias_method :xml_protected_to_xml, :to_xml
17
+ include InstanceMethods
18
+ end
19
+ end
20
+ end
21
+
22
+ module InstanceMethods
23
+ def to_xml(options = {})
24
+ options[:except] ||= []
25
+ xml_protected_to_xml(options.merge(:except => options[:except].concat(self.xml_protected_attrs)))
26
+ end
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moorage-xml_protected
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
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.
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/moorage/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
+