github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

thrivesmart / xml_protected

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 3
    • 1
  • Source
  • Commits
  • Network (1)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

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, ...] — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

readme fix 
moorage (author)
Wed Oct 01 15:33:29 -0700 2008
commit  34dc2eb79de28ae4a2aba0d3b58341e43e7eafe4
tree    fb052c33abe0b2a97caccb841280a843d0bc0622
parent  a415d6e0d61c8d6bbbdd7822d491650b0a9a47da
xml_protected /
name age
history
message
file .gitignore Loading commit data...
file LICENSE
file README.textile
file Rakefile
directory lib/
directory tasks/
directory test/
file xml_protected.gemspec
README.textile

XmlProtected

Keeps specified attributes of a model out of to_xml, by aliasing to_xml, and automatically sending in the correct :excludes to the original to_xml method, e.g. :excludes => [:attr1, :attr2, ...]

NOTE: as of this time, it doesn’t protect these attributes from reading. For that, use this in conjunction with :attr_protected

Usage

An ActiveRecord Model:

class Model < ActiveRecord::Base
  include XmlProtected # Required because it's a gemmefied plugin
  xml_protected :attr1, :attr2, :attr3
end

You can also access these attributes from the added class method:

protected_xml_attributes

In Conjunction with attr_protected

class Model < ActiveRecord::Base
  include XmlProtected # Required because it's a gemmefied plugin
  attr_protected :attr1, :attr2, :attr3
  xml_protected :attr1, :attr2, :attr3
end

Installation

To enable the library your Rails 2.1 (or greater) project, use the gem configuration method in “config/environment.rb”

Rails::Initializer.run do |config|
  config.gem 'thrivesmart-xml_protected', :lib => 'xml_protected', :source => 'http://gems.github.com'
end

The :lib is important, because rails gets confused when the name of the gem is different from the library.

And of course, run

  rake gems:install

To get them installed on your system.

Optionally, to unpack it into your application, just run:

  rake gems:unpack GEM=thrivesmart-xml_protected

How it works

Two methods are extended onto your active record class:

1. xml_protected(*attributes)
2. protected_xml_attributes

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

2. Simply returns the values currently in “xml_protected_attrs”.

One method is included into your active record class, which is pretty self explanatory:

  def to_xml(options = {})
    xml_protected_to_xml(
      options.merge(
        :except => self.class.protected_xml_attributes + (options[:except] || [])
    ))
  end

Copyright & License

Copyright © 2008 ThriveSmart, LLC, released under the MIT license

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server