Class RubyAMF::MappingSet
In: lib/rubyamf/class_mapping.rb
Parent: ::RocketAMF::MappingSet

Advanced mapping container to support various serialization customization settings. Used by RubyAMF class mapper to store advanced mappings.

Methods

Classes and Modules

Class RubyAMF::MappingSet::Mapping

Constants

SERIALIZATION_PROPS = [:except, :only, :methods, :include, :ignore_fields]

Public Class methods

[Source]

    # File lib/rubyamf/class_mapping.rb, line 16
16:     def initialize
17:       @as_mappings = {}
18:       @ruby_mappings = {}
19:       map_defaults
20:     end

Public Instance methods

Returns the actionscript class name mapped to the given ruby class name. Returns nil if not found.

[Source]

    # File lib/rubyamf/class_mapping.rb, line 69
69:     def get_as_class_name ruby_class_name
70:       mapping = @ruby_mappings[ruby_class_name]
71:       return mapping.nil? ? nil : mapping.as
72:     end

Returns the ruby class name mapped to the given actionscript class name. Returns nil if not found.

[Source]

    # File lib/rubyamf/class_mapping.rb, line 76
76:     def get_ruby_class_name as_class_name
77:       mapping = @as_mappings[as_class_name]
78:       return mapping.nil? ? nil : mapping.ruby
79:     end

Map a given actionscript class to a ruby class. You can also control which properties are serialized using :except, :only, :methods, :include for relations, and :ignore_fields for skipping certain fields during deserialization.

Use fully qualified names for both.

Examples:

  m.map :as => 'com.example.Date', :ruby => 'Example::Date'
  m.map :flash => 'User', :ruby => 'User', :only => 'username'
  m.map :flash => 'User', :ruby => 'User', :scope => :other, :include => [:courses, :teacher]

[Source]

    # File lib/rubyamf/class_mapping.rb, line 34
34:     def map params
35:       # Extract and validate ruby and AS class names
36:       ruby_class = params[:ruby]
37:       as_class = params[:as] || params[:flash] || params[:actionscript]
38:       raise "Must pass ruby class name under :ruby key" unless ruby_class
39:       raise "Must pass as class name under :flash, :as, or :actionscript key" unless as_class
40: 
41:       # Get mapping if it already exists
42:       mapping = @as_mappings[as_class] || @ruby_mappings[ruby_class] || Mapping.new
43:       mapping.ruby = ruby_class
44:       mapping.as = as_class
45:       @as_mappings[as_class] = mapping
46:       @ruby_mappings[ruby_class] = mapping
47: 
48:       # If they tried to configure the serialization props, store that too under the proper scope
49:       serialization_config = {}
50:       params.each {|k,v| serialization_config[k] = v if SERIALIZATION_PROPS.include?(k)}
51:       if serialization_config.length > 0
52:         # Determine scope
53:         scope = nil
54:         if params[:default_scope]
55:           scope = mapping.default_scope = params[:default_scope]
56:         elsif params[:scope]
57:           scope = params[:scope]
58:         else
59:           scope = mapping.default_scope
60:         end
61: 
62:         # Add config to scope hash
63:         mapping.scopes[scope.to_sym] = serialization_config
64:       end
65:     end

Returns the property serialization config for the given ruby class name and scope. If scope is nil, it uses the default scope.

[Source]

    # File lib/rubyamf/class_mapping.rb, line 83
83:     def serialization_config ruby_class_name, scope = nil
84:       mapping = @ruby_mappings[ruby_class_name]
85:       if mapping.nil?
86:         nil
87:       else
88:         scope ||= mapping.default_scope
89:         mapping.scopes[scope.to_sym]
90:       end
91:     end

[Validate]