Class: RubyAMF::Configuration::ClassMappings

Inherits:
Object
  • Object
show all
Extended by:
Exceptions
Defined in:
lib/revent/amf3/app/configuration.rb

Overview

ClassMappings configuration support class

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.assume_typesObject

Returns the value of attribute assume_types.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def assume_types
  @assume_types
end

.attribute_namesObject

Returns the value of attribute attribute_names.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def attribute_names
  @attribute_names
end

.check_for_associationsObject

Returns the value of attribute check_for_associations.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def check_for_associations
  @check_for_associations
end

.current_mapping_scopeObject

Returns the value of attribute current_mapping_scope.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def current_mapping_scope
  @current_mapping_scope
end

.default_mapping_scopeObject

Returns the value of attribute default_mapping_scope.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def default_mapping_scope
  @default_mapping_scope
end

.force_active_record_idsObject

Returns the value of attribute force_active_record_ids.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def force_active_record_ids
  @force_active_record_ids
end

.hash_key_accessObject

Returns the value of attribute hash_key_access.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def hash_key_access
  @hash_key_access
end

.ignore_fieldsObject

Returns the value of attribute ignore_fields.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def ignore_fields
  @ignore_fields
end

.translate_caseObject

Returns the value of attribute translate_case.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def translate_case
  @translate_case
end

.use_array_collectionObject

Returns the value of attribute use_array_collection.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def use_array_collection
  @use_array_collection
end

.use_ruby_date_timeObject

Returns the value of attribute use_ruby_date_time.



31
32
33
# File 'lib/revent/amf3/app/configuration.rb', line 31

def use_ruby_date_time
  @use_ruby_date_time
end

Class Method Details

.get_vo_mapping_for_actionscript_class(actionscript_class) ⇒ Object



73
74
75
# File 'lib/revent/amf3/app/configuration.rb', line 73

def get_vo_mapping_for_actionscript_class(actionscript_class)
  @class_mappings_by_actionscript_class[actionscript_class]
end

.get_vo_mapping_for_ruby_class(ruby_class) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/revent/amf3/app/configuration.rb', line 62

def get_vo_mapping_for_ruby_class(ruby_class)
  return unless scoped_class_mapping = @scoped_class_mappings_by_ruby_class[ruby_class] # just in case they didnt specify a ClassMapping for this Ruby Class
  scoped_class_mapping[@current_mapping_scope] ||= (if vo_mapping = @class_mappings_by_ruby_class[ruby_class]
      vo_mapping = vo_mapping.dup # need to duplicate it or else we will overwrite the keys from the original mappings
      vo_mapping[:attributes]   = vo_mapping[:attributes][@current_mapping_scope]||[]   if vo_mapping[:attributes].is_a?(Hash)      # don't include any of these attributes if there is no scope
      vo_mapping[:associations] = vo_mapping[:associations][@current_mapping_scope]||[] if vo_mapping[:associations].is_a?(Hash) # don't include any of these attributes
      vo_mapping
    end
  )
end

.register(mapping) ⇒ Object

register a value object map



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/revent/amf3/app/configuration.rb', line 34

def register(mapping)  #register a value object map
  #build out ignore field logic
  hashed_ignores = {}
  ClassMappings.ignore_fields.to_a.each{|k| hashed_ignores[k] = true} # strings and nils will be put into an array with to_a
  mapping[:ignore_fields].to_a.each{|k| hashed_ignores[k] = true}
  mapping[:ignore_fields] = hashed_ignores # overwrite the original ignore fields

  # if they specify custom attributes, ensure that AR ids are being passed as well if they opt for it.
  if force_active_record_ids && mapping[:attributes] && mapping[:type]=="active_record" && !mapping[:attributes].include?("id")
    mapping[:attributes] << "id"
  end
  
  # created caching hashes for mapping
  @class_mappings_by_ruby_class[mapping[:ruby]] = mapping # for quick referencing purposes
  @class_mappings_by_actionscript_class[mapping[:actionscript]] = mapping # for quick referencing purposes
  @scoped_class_mappings_by_ruby_class[mapping[:ruby]] = {} # used later for caching based on scope (will get cached after the first run)
  # for deserialization - looking up in a hash is faster than looking up in an array.
  begin
    if mapping[:type] == "active_record" 
      @attribute_names[mapping[:ruby]] = (mapping[:ruby].constantize.new.attribute_names + ["id"]).inject({}){|hash, attr| hash[attr]=true ; hash} # include the id attribute
    end
  rescue ActiveRecord::StatementInvalid => e
    # This error occurs during migrations, since the AR constructed above will check its columns, but the table won't exist yet.
    # We'll ignore the error if we're migrating.
    raise unless ARGV.include?("migrate") or ARGV.include?("db:migrate")
  end
end