Class: ActiveAdminImport::Model
- Inherits:
-
Object
- Object
- ActiveAdminImport::Model
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations, ActiveModel::Validations::Callbacks
- Defined in:
- lib/active_admin_import/model.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Instance Method Summary collapse
- #allow_archive? ⇒ Boolean
- #archive? ⇒ Boolean
- #assign_attributes(args = {}, new_record = false) ⇒ Object
- #default_attributes ⇒ Object
- #force_encoding? ⇒ Boolean
-
#initialize(args = {}) ⇒ Model
constructor
A new instance of Model.
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #read_attribute_for_validation(key) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Model
Returns a new instance of Model.
20 21 22 23 24 |
# File 'lib/active_admin_import/model.rb', line 20 def initialize(args={}) @new_record = true @attributes = {} assign_attributes(default_attributes.merge(args), true) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
18 19 20 |
# File 'lib/active_admin_import/model.rb', line 18 def attributes @attributes end |
Instance Method Details
#allow_archive? ⇒ Boolean
47 48 49 |
# File 'lib/active_admin_import/model.rb', line 47 def allow_archive? !!@attributes[:allow_archive] end |
#archive? ⇒ Boolean
67 68 69 |
# File 'lib/active_admin_import/model.rb', line 67 def archive? file_type == 'application/zip' end |
#assign_attributes(args = {}, new_record = false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_admin_import/model.rb', line 26 def assign_attributes(args = {}, new_record = false) @attributes.merge!(args) @new_record = new_record args.keys.each do |key| key = key.to_sym #generate methods for instance object by attributes singleton_class.class_eval do define_method(key) { self.attributes[key] } unless method_defined? key define_method("#{key}=") { |new_value| @attributes[key] = new_value } unless method_defined? "#{key}=" end end if args.is_a?(Hash) end |
#default_attributes ⇒ Object
43 44 45 |
# File 'lib/active_admin_import/model.rb', line 43 def default_attributes {hint: '', file: nil, csv_headers: [], allow_archive: true, force_encoding: 'UTF-8'} end |
#force_encoding? ⇒ Boolean
55 56 57 |
# File 'lib/active_admin_import/model.rb', line 55 def force_encoding? !!@attributes[:force_encoding] end |
#new_record? ⇒ Boolean
51 52 53 |
# File 'lib/active_admin_import/model.rb', line 51 def new_record? !!@new_record end |
#persisted? ⇒ Boolean
63 64 65 |
# File 'lib/active_admin_import/model.rb', line 63 def persisted? false end |
#read_attribute_for_validation(key) ⇒ Object
39 40 41 |
# File 'lib/active_admin_import/model.rb', line 39 def read_attribute_for_validation(key) @attributes[key.to_sym] end |
#to_hash ⇒ Object
59 60 61 |
# File 'lib/active_admin_import/model.rb', line 59 def to_hash @attributes end |