Class: Bukovina::Importers::Common
- Inherits:
-
Object
- Object
- Bukovina::Importers::Common
- Includes:
- FindInit
- Defined in:
- lib/bukovina/importers/common.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #import ⇒ Object
-
#initialize(attrs, o_attrs = {}) ⇒ Common
constructor
A new instance of Common.
- #model ⇒ Object
Methods included from FindInit
#foreign_class, #parse_array, #parse_hash, #separate_hash
Constructor Details
#initialize(attrs, o_attrs = {}) ⇒ Common
Returns a new instance of Common.
24 25 26 |
# File 'lib/bukovina/importers/common.rb', line 24 def initialize attrs, o_attrs = {} @errors = [] @attrs = [ attrs.deep_dup ].flatten ;end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/bukovina/importers/common.rb', line 6 def errors @errors end |
Instance Method Details
#import ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/bukovina/importers/common.rb', line 12 def import @attrs.each do |attrs| (search_attrs, new_attrs) = separate_hash( parse_hash( model, attrs ) ) #binding.pry o = model.where( search_attrs ).first_or_create( new_attrs ) errs = o.errors.map do |field, | StandardError.new("#{field}: #{}") ;end @errors.concat(errs) ;end;end |
#model ⇒ Object
8 9 10 |
# File 'lib/bukovina/importers/common.rb', line 8 def model @model ||= self.class::MODEL.to_s.constantize end |