Module: Six::Import::Model::ClassMethods
- Defined in:
- lib/six-updater-web/vendor/plugins/six-import/lib/six/import.rb
Instance Method Summary collapse
- #blabla(h) ⇒ Object
- #from_hash(hash) ⇒ Object
- #from_json(json) ⇒ Object
-
#from_xml(xml) ⇒ Object
The xml has a surrounding class tag (e.g. ship-to), but the hash has no counterpart (e.g. ‘ship_to’ => {} ).
- #imp ⇒ Object
Instance Method Details
#blabla(h) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/six-updater-web/vendor/plugins/six-import/lib/six/import.rb', line 50 def blabla(h) l = [] h.each_pair do |key, value| case key when self.to_s.downcase c = self.from_hash value l << c end end l end |
#from_hash(hash) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/six-updater-web/vendor/plugins/six-import/lib/six/import.rb', line 87 def from_hash( hash ) h = hash.dup h.each do |key, value| case value.class.to_s when 'Array' h[key].map! { |e| Object.const_get(key.camelize.singularize).from_hash e } when 'Hash' h[key] = Object.const_get(key.camelize).from_hash value end end n = nil previous = nil if h["id"] id = h["id"] h.delete "id" r = nil begin r = self.find(id) rescue end if r previous = r.inspect r.attributes = h n = r else n = self.new h n.id = id end else n = self.new h end logger.debug "#{n.class} #{n.id} #{n.changed?}: #{"#{n.inspect} - #{previous}" if n.changed?}" n.save if n.changed?# || n.new? n end |
#from_json(json) ⇒ Object
124 125 126 127 |
# File 'lib/six-updater-web/vendor/plugins/six-import/lib/six/import.rb', line 124 def from_json( json ) hash = ActiveSupport::JSON.decode json self.from_hash hash end |
#from_xml(xml) ⇒ Object
The xml has a surrounding class tag (e.g. ship-to), but the hash has no counterpart (e.g. ‘ship_to’ => {} )
131 132 133 134 |
# File 'lib/six-updater-web/vendor/plugins/six-import/lib/six/import.rb', line 131 def from_xml( xml ) hash = Hash.from_xml xml self.from_hash hash[self.to_s.underscore] end |
#imp ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/six-updater-web/vendor/plugins/six-import/lib/six/import.rb', line 62 def imp Six::Network::Panel.setlogger(logger) begin Six::Network::Panel.login("", "") rescue ScriptError end path = "/#{self.to_s.pluralize.downcase}/exp/1.json" logger.debug "Path: #{path}" res = Six::Network::Panel.get(path) h = ActiveSupport::JSON.decode res.body k = [] return k unless h case h when Array h.each do |b| k += blabla(b) end when Hash k += blabla h end k end |