Module | RubyAMF::Model::ClassMethods |
In: |
lib/rubyamf/model.rb
|
In-model mapping configuration methods
Specify the actionscript class name that this class maps to.
Example:
class SerializableObject include RubyAMF::Model as_class "com.rubyamf.ASObject" end
# File lib/rubyamf/model.rb, line 48 48: def as_class class_name 49: @as_class = class_name.to_s 50: RubyAMF::ClassMapper.mappings.map :as => @as_class, :ruby => self.name 51: end
Define a parameter mapping for the default scope or a given scope. If the first parameter is a hash, it looks for a :default_scope key to set the default scope and scope the given configuration, and parses the other keys like serializable_hash does. If the first argument is a symbol, that symbol is assumed to be the scope for the given configuration. Just like serializable_hash, it supports :except, :only, :methods, and :include for relations. It also has an :ignore_fields configuration for skipping certain fields during deserialization if the actionscript object contains extra fields or to protect yourself from modification of protected properties. :ignore_fields must be defined on the default scope, or it will be ignored.
Example:
class SerializableObject include RubyAMF::Model as_class "com.rubyamf.ASObject" map_amf :only => "prop_a" map_amf :testing, :only => "prop_b" map_amf :default_scope => :asdf, :only => "prop_c", :ignore_fields => ["password", "password_confirm"] end
# File lib/rubyamf/model.rb, line 78 78: def map_amf scope_or_options=nil, options=nil 79: # Make sure they've already called as_class first 80: raise "Must define as_class first" unless @as_class 81: 82: # Format parameters to pass to RubyAMF::MappingSet#map 83: if options 84: options[:scope] = scope_or_options 85: else 86: options = scope_or_options 87: end 88: options[:as] = @as_class 89: options[:ruby] = self.name 90: RubyAMF::ClassMapper.mappings.map options 91: end