Class: Zena::Loader::YamlLoader
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Zena::Loader::YamlLoader
- Defined in:
- lib/zena/loader/yaml_loader.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create_or_update(opts) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/zena/loader/yaml_loader.rb', line 13 def create_or_update(opts) h = {} opts.each_pair do |k,v| if :type == k h['_type_'] = v else h[k.to_s] = v end end if h['id'] && obj = find_by_id(h['id']) res = [] h.each do |k,v| res << "`#{k}` = #{v ? v.inspect : 'NULL'}" end connection.execute "UPDATE #{table_name} SET #{res.join(', ')} WHERE id = #{h['id']}" else keys = [] values = [] h.each do |k,v| keys << "`#{k}`" values << (v ? v.inspect : 'NULL') end connection.execute "INSERT INTO #{table_name} (#{keys.join(', ')}) VALUES (#{values.join(', ')})" end end |
.set_table(tbl) ⇒ Object
8 9 10 11 |
# File 'lib/zena/loader/yaml_loader.rb', line 8 def set_table(tbl) set_table_name tbl reset_column_information end |
Instance Method Details
#_type_=(t) ⇒ Object
45 46 47 |
# File 'lib/zena/loader/yaml_loader.rb', line 45 def _type_=(t) self.type = t end |
#site_id=(i) ⇒ Object
41 42 43 |
# File 'lib/zena/loader/yaml_loader.rb', line 41 def site_id=(i) self[:site_id] = i end |