Class: Import
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Import
- Defined in:
- app/models/import.rb
Overview
A class used for transient data, primarily in the development of import scripts.
Possible usage
i = Import.find_or_create_by_name('My Import')
# set some values
my_values = ['a', 'b', 'c']
i.set('my_values_name', my_values)
i.get('my_values_name') # => ['a', 'b', 'c']
Instance Attribute Summary collapse
-
#metadata ⇒ Hstore
A Hstore column.
-
#metadata_json ⇒ Json
A JSON column.
-
#name ⇒ String
Required, the lookup name.
Instance Method Summary collapse
Methods inherited from ApplicationRecord
Instance Attribute Details
#metadata ⇒ Hstore
Returns a Hstore column.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/import.rb', line 28 class Import < ApplicationRecord store_accessor :metadata validates_presence_of :name validates_uniqueness_of :name def set(key, value) h = h ||= {} h[key] = value update_attribute(:metadata_json, h) end def get(key) return nil if .nil? [key] end end |
#metadata_json ⇒ Json
Returns a JSON column.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/import.rb', line 28 class Import < ApplicationRecord store_accessor :metadata validates_presence_of :name validates_uniqueness_of :name def set(key, value) h = h ||= {} h[key] = value update_attribute(:metadata_json, h) end def get(key) return nil if .nil? [key] end end |
#name ⇒ String
Returns required, the lookup name.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/import.rb', line 28 class Import < ApplicationRecord store_accessor :metadata validates_presence_of :name validates_uniqueness_of :name def set(key, value) h = h ||= {} h[key] = value update_attribute(:metadata_json, h) end def get(key) return nil if .nil? [key] end end |
Instance Method Details
#get(key) ⇒ Object
41 42 43 44 |
# File 'app/models/import.rb', line 41 def get(key) return nil if .nil? [key] end |
#set(key, value) ⇒ Object
34 35 36 37 38 39 |
# File 'app/models/import.rb', line 34 def set(key, value) h = h ||= {} h[key] = value update_attribute(:metadata_json, h) end |