Class: ActiveRecord::Base
- Inherits:
-
Object
- Object
- ActiveRecord::Base
- Defined in:
- lib/ruboss4ruby/active_foo.rb
Overview
Flex friendly XML serialization patches
Class Method Summary collapse
- .default_fxml_hash(already_included = []) ⇒ Object
- .default_fxml_includes(*args) ⇒ Object
-
.default_fxml_methods(*args) ⇒ Object
TODO: this doesn’t work with hash based to_fxml(:include) options, only array based.
-
.includes_as_hash(includes = nil) ⇒ Object
options can be a Hash, Array, Symbol or nil.
Class Method Details
.default_fxml_hash(already_included = []) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/ruboss4ruby/active_foo.rb', line 134 def default_fxml_hash(already_included = []) # return {} unless self.class.respond_to?(:default_fxml_include_params) || self.class.respond_to?(:default_fxml_methods_array) default_hash = {:include => {}} default_hash[:methods] = self.default_fxml_methods_array if self.respond_to?(:default_fxml_methods_array) if self.respond_to?(:default_fxml_include_params) default_includes = self.default_fxml_include_params default_hash[:include] = default_includes.inject({}) do |include_hash, included| next if already_included.include?(included) # We only want to include things once, to avoid infinite loops included_class = included.to_s.singularize.camelize.constantize include_hash[included] = included_class.default_fxml_hash(already_included + default_includes) include_hash end end default_hash end |
.default_fxml_includes(*args) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/ruboss4ruby/active_foo.rb', line 125 def default_fxml_includes(*args) includes = *args.dup module_eval <<-END def self.default_fxml_include_params return [#{includes.inspect}].flatten end END end |
.default_fxml_methods(*args) ⇒ Object
TODO: this doesn’t work with hash based to_fxml(:include) options, only array based
116 117 118 119 120 121 122 123 |
# File 'lib/ruboss4ruby/active_foo.rb', line 116 def default_fxml_methods(*args) methods = *args.dup module_eval <<-END def self.default_fxml_methods_array return [#{methods.inspect}].flatten end END end |
.includes_as_hash(includes = nil) ⇒ Object
options can be a Hash, Array, Symbol or nil. We always want it as a Hash. This translates includes to a Hash like this: If it’s a nil, return an empty Hash ({}) If it’s a Hash, then it is just returned If it’s an array, then it returns a Hash with each array element as a key, and values of empty Hashes. If it’s a symbol, then it returns a Hash with a single key/value pair, with the symbol as the key and an empty Hash as the value.
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ruboss4ruby/active_foo.rb', line 156 def includes_as_hash(includes = nil) res = case when includes.is_a?(Hash) includes when includes.nil? {} else #Deal with arrays and symbols res = [includes].flatten.inject({}) {|include_hash, included| include_hash[included] = {} ; include_hash} end res end |