Class RubyAMF::Configuration
In: lib/rubyamf/configuration.rb
Parent: Object

RubyAMF configuration container. It can be accessed by calling RubyAMF.configuration, or modified in a block like so:

  RubyAMF.configure do |config|
    config.gateway_path = "/amf"
  end

Gateway configuration

Gateway configuration includes the gateway path and details about parameter mapping.

gateway_path:Default: "/rubyamf/gateway". The URL that responds to AMF requests. The URL should start with a "/" and not end with a "/".
populate_params_hash:Default: true. For Rails users, all amf parameters can be accessed in the controller by calling rubyamf_params. If enabled, the amf parameters are merged into the params hash as well.
show_html_gateway:Default: true. If enabled, non-AMF requests to the gateway url will result in a simple HTML page being returned.
param_mappings:A hash that stores parameter mappings. Should only be modified through calls to map_params

Serialization options

RubyAMF provides a wide variety of customization options for serialization to simplify integration.

translate_case:Default: false. If enabled, properties will be converted to underscore style on deserialization from actionscript and will be converted to camelcase on serialization. This allows you to use language appropriate case style and have RubyAMF automatically care of translation.
auto_class_mapping:Default: false. If a class mapping for a given ruby or actionscript class has not been defined, automatically maps it during serialization or deserialization. Nested ruby or actionscript classes will be automatically mapped to the class name without the namespace. Example: com.rubyamf.User => User or RubyAMF::User => User.
use_array_collection:Default: false. If enabled, all arrays will be serialized as ArrayCollection objects. You can override this on a per-array basis by setting is_array_collection on the array to true or false. (Implementation in RocketAMF)
hash_key_access:Default: :symbol. If set to :string, all deserialized hashes have the keys as strings. RocketAMF defaults to symbols, so setting to :string will reduce performance and increase memory usage.
preload_models:If you are using in-model mapping and don‘t have auto_class_mapping enabled, you may need to force classes to be loaded before mapping takes effect. Simply include all necessary classes as strings to have RubyAMF force them to be loaded on initialization. Example: config.preload_models = ["User", "Course"]
check_for_associations:Default: true. If enabled, associations that have been pre-loaded, either through :include or simply by being accessed, will be automatically included during serialization without any additional configuration.
ignore_fields:Default: [‘created_at’, ‘created_on’, ‘updated_at’, ‘updated_on’]. A list of all properties that should not be serialized unless they show up in the :only => [:prop] class mapping config for that object. Completely separate from the :ignore_fields config for class mapping, which affects deserialization.

Methods

Attributes

auto_class_mapping  [RW]  Serialization options
check_for_associations  [RW]  Serialization options
gateway_path  [RW]  Gateway options
hash_key_access  [RW]  Serialization options
ignore_fields  [RW]  Serialization options
param_mappings  [R] 
populate_params_hash  [RW]  Gateway options
preload_models  [RW]  Serialization options
show_html_gateway  [RW]  Gateway options
translate_case  [RW]  Serialization options
use_array_collection  [RW]  Serialization options

Public Class methods

[Source]

     # File lib/rubyamf/configuration.rb, line 88
 88:     def initialize
 89:       @gateway_path = "/rubyamf/gateway"
 90:       @param_mappings = {}
 91:       @populate_params_hash = true
 92:       @show_html_gateway = true
 93: 
 94:       @translate_case = false
 95:       @auto_class_mapping = false
 96:       @use_array_collection = false
 97:       @hash_key_access = :symbol
 98:       @preload_models = []
 99:       @check_for_associations = true
100:       @ignore_fields = ['created_at', 'created_on', 'updated_at', 'updated_on']
101:     end

Public Instance methods

Returns the class mapper class being used

[Source]

     # File lib/rubyamf/configuration.rb, line 119
119:     def class_mapper
120:       if @class_mapper.nil?
121:         @class_mapper = RubyAMF::ClassMapping
122:       end
123:       @class_mapper
124:     end

Set to the class of any conforming class mapper to use it instead of RubyAMF::ClassMapping. If you don‘t need any of the advanced features offered by the RubyAMF class mapper, you can gain some substantial performance improvements by settings this to RocketAMF::Ext::FastClassMapping or RocketAMF::ClassMapping for the slower pure-ruby version.

[Source]

     # File lib/rubyamf/configuration.rb, line 132
132:     def class_mapper= klass
133:       @class_mapper = klass
134:     end

Loads the legacy config file at the given path or tries to locate it by looking for a rubyamf_config.rb file in several possible locations. Automatically run by RubyAMF if you are using Rails 2, it should be run before any additional configuration if you are not using Rails 2, as it overrides all previous configuration.

[Source]

     # File lib/rubyamf/configuration.rb, line 141
141:     def load_legacy path=nil
142:       # Locate legacy config
143:       unless path
144:         possible = []
145:         possible << File.join(RAILS_ROOT, 'config', 'rubyamf_config.rb') if defined?(RAILS_ROOT)
146:         possible << File.join('config', 'rubyamf_config.rb')
147:         possible << 'rubyamf_config.rb'
148:         unless path = possible.find {|p| File.exists?(p)}
149:           raise "rubyamf_config.rb not found"
150:         end
151:       end
152: 
153:       # Load legacy config
154:       $" << "app/configuration" # prevent legacy code require from doing anything
155:       LegacySandbox.module_eval(File.read(path))
156:       $".pop
157:       cm = LegacySandbox::RubyAMF::ClassMappings
158:       pm = LegacySandbox::RubyAMF::ParameterMappings
159: 
160:       # Raise exceptions for disabled settings
161:       if cm.force_active_record_ids != nil; raise "CONFIG PARSE ERROR: force_active_record_ids is no longer supported. Use ignore_fields if you want to prevent the id from being serialized."; end
162:       if cm.hash_key_access == :indifferent; raise "CONFIG PARSE ERROR: indifferent hash_key_access is not supported for performance reasons. Use either :string or :symbol, the default."; end
163:       if cm.default_mapping_scope != nil; raise "CONFIG PARSE ERROR: default_mapping_scope is not supported globally. Please log a feature request if you need it, or use switch to the new config syntax which supports per-model defaults."; end
164:       if cm.use_ruby_date_time == true; raise "CONFIG PARSE ERROR: use_ruby_date_time is not supported by RocketAMF. Please log a feature request if you need it."; end
165:       if pm.scaffolding == true; raise "CONFIG PARSE ERROR: scaffolding is not supported. Please log a feature request if you need it."; end
166: 
167:       # Populate ClassMappings configs from legacy config
168:       @ignore_fields = cm.ignore_fields unless cm.ignore_fields.nil?
169:       @translate_case = cm.translate_case if cm.translate_case == true
170:       @hash_key_access = cm.hash_key_access unless cm.hash_key_access.nil?
171:       @use_array_collection = cm.use_array_collection if cm.use_array_collection == true
172:       @check_for_associations = cm.check_for_associations if cm.check_for_associations == false
173:       mapset = class_mapper.mappings
174:       (cm.mappings || []).each do |legacy_mapping|
175:         mapping = {}
176:         if legacy_mapping[:type] == 'active_resource'
177:           raise "CONFIG PARSE ERROR: active_resource mapping type is not supported. Please log a feature request or stop using it."
178:         end
179: 
180:         # Extract unscoped settings
181:         mapping[:as] = legacy_mapping[:actionscript]
182:         mapping[:ruby] = legacy_mapping[:ruby]
183:         mapping[:methods] = legacy_mapping[:methods] unless legacy_mapping[:methods].nil?
184:         mapping[:ignore_fields] = legacy_mapping[:ignore_fields] unless legacy_mapping[:ignore_fields].nil?
185: 
186:         # Process possibly scoped settings
187:         attrs = legacy_mapping[:attributes]
188:         assoc = legacy_mapping[:associations]
189:         if attrs.is_a?(Hash) || assoc.is_a?(Hash)
190:           # Extract scopes
191:           scopes = []
192:           scopes += attrs.keys if attrs.is_a?(Hash)
193:           scopes += assoc.keys if assoc.is_a?(Hash)
194: 
195:           # Build settings for scopes
196:           scopes.each do |scope|
197:             scoped = mapping.dup
198:             scoped[:scope] = scope.to_sym
199:             scoped[:only] = attrs.is_a?(Hash) ? attrs[scope] : attrs
200:             scoped.delete(:only) if scoped[:only].nil?
201:             scoped[:include] = assoc.is_a?(Hash) ? assoc[scope] : assoc
202:             scoped.delete(:include) if scoped[:include].nil?
203:             mapset.map scoped
204:           end
205:         else
206:           # No scoping
207:           mapping[:only] = attrs unless attrs.nil?
208:           mapping[:include] = assoc unless assoc.nil?
209:           mapset.map mapping
210:         end
211:       end
212: 
213:       # Populate ParameterMapping configs from legacy config
214:       @populate_params_hash = pm.always_add_to_params if pm.always_add_to_params == false
215:       (pm.mappings || []).each do |m|
216:         params = []
217:         m[:params].each do |k, v|
218:           unless v =~ /\[(\d+)\]/
219:             raise "CONFIG PARSE ERROR: parameter mappings are no longer evalled - '#{v}' must match [DIGITS]. Please log a feature request if you need this."
220:           end
221:           params[$1.to_i] = k
222:         end
223:         self.map_params m[:controller], m[:action], params
224:       end
225: 
226:       # Reset sandbox
227:       cm.reset
228:       pm.reset
229: 
230:       self
231:     end

Maps the given array of named parameters to the arguments for calls to the given controller and action. For Rails users, the prefered method of parameter mapping is through routing (see RubyAMF::Rails::Routing).

Example:

  config.map_params "UserController", "login", [:session_token, :username, :password]
  # params hash => {
  #   0 => "asdf", 1 => "user", 2 => "pass",
  #   :session_token => "asdf", :username => "user", :password => "pass"
  # }

[Source]

     # File lib/rubyamf/configuration.rb, line 114
114:     def map_params controller, action, params
115:       @param_mappings[controller.to_s+"#"+action.to_s] = params
116:     end

[Validate]