Module: RubyAMF::Model::ClassMethods
- Defined in:
- lib/rubyamf/model.rb
Overview
In-model mapping configuration methods
Instance Method Summary collapse
-
#as_class(class_name) ⇒ Object
(also: #actionscript_class, #flash_class, #amf_class)
Specify the actionscript class name that this class maps to.
-
#map_amf(scope_or_options = nil, options = nil) ⇒ Object
Define a parameter mapping for the default scope or a given scope.
Instance Method Details
#as_class(class_name) ⇒ Object Also known as: actionscript_class, flash_class, amf_class
48 49 50 51 |
# File 'lib/rubyamf/model.rb', line 48 def as_class class_name @as_class = class_name.to_s RubyAMF::ClassMapper.mappings.map :as => @as_class, :ruby => self.name end |
#map_amf(scope_or_options = nil, options = nil) ⇒ Object
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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rubyamf/model.rb', line 78 def map_amf =nil, =nil # Make sure they've already called as_class first raise "Must define as_class first" unless @as_class # Format parameters to pass to RubyAMF::MappingSet#map if [:scope] = else = end [:as] = @as_class [:ruby] = self.name RubyAMF::ClassMapper.mappings.map end |