Class: ActiveAdminImport::Model
- Inherits:
-
Object
- Object
- ActiveAdminImport::Model
- Includes:
- ActiveModel::Model, ActiveModel::Validations, ActiveModel::Validations::Callbacks
- Defined in:
- lib/active_admin_import/model.rb
Defined Under Namespace
Modules: CONST
Instance Attribute Summary collapse
-
#attributes ⇒ Object
(also: #to_hash)
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
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
Constructor Details
#initialize(args = {}) ⇒ Model
Returns a new instance of Model.
44 45 46 47 48 |
# File 'lib/active_admin_import/model.rb', line 44 def initialize(args = {}) @new_record = true @attributes = {} assign_attributes(default_attributes.merge(args), true) end |
Instance Attribute Details
#attributes ⇒ Object (readonly) Also known as: to_hash
Returns the value of attribute attributes.
42 43 44 |
# File 'lib/active_admin_import/model.rb', line 42 def attributes @attributes end |
Class Method Details
.define_get_method(attr_name) ⇒ Object
191 192 193 194 |
# File 'lib/active_admin_import/model.rb', line 191 def define_get_method(attr_name) return if method_defined? "#{attr_name}=" define_method("#{attr_name}=") { |new_value| @attributes[attr_name] = new_value } end |
.define_set_method(attr_name) ⇒ Object
186 187 188 189 |
# File 'lib/active_admin_import/model.rb', line 186 def define_set_method(attr_name) return if method_defined? attr_name define_method(attr_name) { attributes[attr_name] } end |
Instance Method Details
#allow_archive? ⇒ Boolean
73 74 75 |
# File 'lib/active_admin_import/model.rb', line 73 def allow_archive? attributes[:allow_archive].present? end |
#archive? ⇒ Boolean
89 90 91 |
# File 'lib/active_admin_import/model.rb', line 89 def archive? file_type == CONST::ZIP_TYPE end |
#assign_attributes(args = {}, new_record = false) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/active_admin_import/model.rb', line 50 def assign_attributes(args = {}, new_record = false) args[:file] = nil unless args.key?(:file) @attributes.merge!(args) @new_record = new_record args.keys.each do |key| define_methods_for(key.to_sym) end if args.is_a?(Hash) end |
#default_attributes ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/active_admin_import/model.rb', line 63 def default_attributes { allow_archive: true, csv_headers: [], file: nil, force_encoding: 'UTF-8', hint: '' } end |
#force_encoding? ⇒ Boolean
81 82 83 |
# File 'lib/active_admin_import/model.rb', line 81 def force_encoding? attributes[:force_encoding].present? end |
#new_record? ⇒ Boolean
77 78 79 |
# File 'lib/active_admin_import/model.rb', line 77 def new_record? @new_record.present? end |
#persisted? ⇒ Boolean
85 86 87 |
# File 'lib/active_admin_import/model.rb', line 85 def persisted? false end |
#read_attribute_for_validation(key) ⇒ Object
59 60 61 |
# File 'lib/active_admin_import/model.rb', line 59 def read_attribute_for_validation(key) @attributes[key.to_sym] end |