Class: Pump::Encoder
- Inherits:
-
Object
- Object
- Pump::Encoder
- Defined in:
- lib/pump/encoder.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#encoder_config ⇒ Object
readonly
Returns the value of attribute encoder_config.
-
#encoder_options ⇒ Object
readonly
Returns the value of attribute encoder_options.
-
#root_name ⇒ Object
readonly
Returns the value of attribute root_name.
Instance Method Summary collapse
-
#encode(object, options = {}) ⇒ String
Encode a object or an array of objects to an formatted string.
-
#initialize(root_name, encoder_config = nil, encoder_options = {}) { ... } ⇒ self
constructor
Creates a new XML-encoder with a root tag named after +root_name+.
Constructor Details
#initialize(root_name, encoder_config = nil, encoder_options = {}) { ... } ⇒ self
Creates a new XML-encoder with a root tag named after +root_name+.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pump/encoder.rb', line 32 def initialize(root_name, encoder_config=nil, ={}, &blk) if encoder_config.is_a?(Array) @encoder_config = encoder_config @encoder_options = || {} else raise ArgumentError unless block_given? @encoder_options = encoder_config || {} @encoder_config = Pump::Dsl.new(&blk).config end @root_name = root_name merge_base compile_field_map compile end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
5 6 7 |
# File 'lib/pump/encoder.rb', line 5 def base @base end |
#encoder_config ⇒ Object (readonly)
Returns the value of attribute encoder_config.
5 6 7 |
# File 'lib/pump/encoder.rb', line 5 def encoder_config @encoder_config end |
#encoder_options ⇒ Object (readonly)
Returns the value of attribute encoder_options.
5 6 7 |
# File 'lib/pump/encoder.rb', line 5 def @encoder_options end |
#root_name ⇒ Object (readonly)
Returns the value of attribute root_name.
5 6 7 |
# File 'lib/pump/encoder.rb', line 5 def root_name @root_name end |
Instance Method Details
#encode(object, options = {}) ⇒ String
Encode a object or an array of objects to an formatted string.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pump/encoder.rb', line 55 def encode(object, ={}) object = object.to_a if defined?(ActiveRecord::Relation) && object.is_a?(ActiveRecord::Relation) fields_to_hash() if object.is_a?(Array) if [:fields] encode_partial_array(object, ) else encode_array(object, ) end elsif [:fields] encode_partial_single(object, ) else encode_single(object, ) end end |