Class: RestfulX::AMF::ClassMapping::MappingSet
- Inherits:
-
Object
- Object
- RestfulX::AMF::ClassMapping::MappingSet
- Defined in:
- lib/restfulx/amf/class_mapping.rb
Instance Attribute Summary collapse
-
#default_as_prefix ⇒ Object
Returns the value of attribute default_as_prefix.
Instance Method Summary collapse
-
#get_as_class_name(class_name) ⇒ Object
Returns the AS class name for the given ruby class name, returing nil if not found.
-
#get_ruby_class_name(class_name) ⇒ Object
Returns the ruby class name for the given AS class name, returing nil if not found.
-
#initialize ⇒ MappingSet
constructor
:nodoc:.
-
#map(params) ⇒ Object
Map a given AS class to a ruby class.
Constructor Details
#initialize ⇒ MappingSet
:nodoc:
6 7 8 9 10 |
# File 'lib/restfulx/amf/class_mapping.rb', line 6 def initialize #:nodoc: @as_mappings = {} @ruby_mappings = {} @default_as_prefix = "" end |
Instance Attribute Details
#default_as_prefix ⇒ Object
Returns the value of attribute default_as_prefix.
4 5 6 |
# File 'lib/restfulx/amf/class_mapping.rb', line 4 def default_as_prefix @default_as_prefix end |
Instance Method Details
#get_as_class_name(class_name) ⇒ Object
Returns the AS class name for the given ruby class name, returing nil if not found
34 35 36 37 38 39 40 41 |
# File 'lib/restfulx/amf/class_mapping.rb', line 34 def get_as_class_name(class_name) #:nodoc: unless as_class_name = @ruby_mappings[class_name.to_s] as_class_name = "#{@default_as_prefix}.#{class_name}" @as_mappings[as_class_name] = class_name.to_s @ruby_mappings[class_name.to_s] = as_class_name end as_class_name end |
#get_ruby_class_name(class_name) ⇒ Object
Returns the ruby class name for the given AS class name, returing nil if not found
45 46 47 48 49 50 51 52 |
# File 'lib/restfulx/amf/class_mapping.rb', line 45 def get_ruby_class_name(class_name) #:nodoc: unless ruby_class_name = @as_mappings[class_name.to_s] ruby_class_name = class_name.sub("#{default_as_prefix}.", "") @ruby_mappings[ruby_class_name] = class_name.to_s @as_mappings[class_name.to_s] = ruby_class_name end ruby_class_name end |
#map(params) ⇒ Object
Map a given AS class to a ruby class.
Use fully qualified names for both.
Example:
m.map :as 'com.example.Date', :ruby => 'Example::Date'
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/restfulx/amf/class_mapping.rb', line 19 def map(params) [:as, :ruby].each {|k| params[k] = params[k].to_s if params[k] } # Convert params to strings if params.key?(:as) and params.key?(:ruby) @as_mappings[params[:as]] = params[:ruby] @ruby_mappings[params[:ruby]] = params[:as] end if params.key?(:as) params[:ruby] = get_ruby_class_name(params[:as]) end end |