Module: SelectiveAttributeProxy
- Included in:
- AWS::S3::ACL::Grant, AWS::S3::ACL::Grantee, AWS::S3::ACL::Policy, AWS::S3::Logging::Status, AWS::S3::Owner, AWS::S3::S3Object
- Defined in:
- lib/aws/s3/extensions.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Class Method Details
.included(klass) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/aws/s3/extensions.rb', line 264 def self.included(klass) klass.extend(ClassMethods) klass.class_eval(" cattr_accessor :attribute_proxy\n cattr_accessor :attribute_proxy_options\n \n # Default name for attribute storage\n self.attribute_proxy = :attributes\n self.attribute_proxy_options = {:exclusively => true}\n \n private\n # By default proxy all attributes\n def proxiable_attribute?(name)\n return true unless self.class.attribute_proxy_options[:exclusively]\n send(self.class.attribute_proxy).has_key?(name)\n end\n \n def method_missing(method, *args, &block)\n # Autovivify attribute storage\n if method == self.class.attribute_proxy\n ivar = \"@\\\#{method}\"\n instance_variable_set(ivar, {}) unless instance_variable_get(ivar).is_a?(Hash)\n instance_variable_get(ivar)\n # Delegate to attribute storage\n elsif method.to_s =~ /^(\\\\w+)(=?)$/ && proxiable_attribute?($1)\n attributes_hash_name = self.class.attribute_proxy\n $2.empty? ? send(attributes_hash_name)[$1] : send(attributes_hash_name)[$1] = args.first\n else\n super\n end\n end\n EVAL\nend\n", __FILE__, __LINE__) |