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
190 191 192 193 |
# File 'lib/active_admin_import/model.rb', line 190 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
185 186 187 188 |
# File 'lib/active_admin_import/model.rb', line 185 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
72 73 74 |
# File 'lib/active_admin_import/model.rb', line 72 def allow_archive? attributes[:allow_archive].present? end |
#archive? ⇒ Boolean
88 89 90 |
# File 'lib/active_admin_import/model.rb', line 88 def archive? file_type == CONST::ZIP_TYPE end |
#assign_attributes(args = {}, new_record = false) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/active_admin_import/model.rb', line 50 def assign_attributes(args = {}, new_record = false) @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
62 63 64 65 66 67 68 69 70 |
# File 'lib/active_admin_import/model.rb', line 62 def default_attributes { allow_archive: true, csv_headers: [], file: nil, force_encoding: 'UTF-8', hint: '' } end |
#force_encoding? ⇒ Boolean
80 81 82 |
# File 'lib/active_admin_import/model.rb', line 80 def force_encoding? attributes[:force_encoding].present? end |
#new_record? ⇒ Boolean
76 77 78 |
# File 'lib/active_admin_import/model.rb', line 76 def new_record? @new_record.present? end |
#persisted? ⇒ Boolean
84 85 86 |
# File 'lib/active_admin_import/model.rb', line 84 def persisted? false end |
#read_attribute_for_validation(key) ⇒ Object
58 59 60 |
# File 'lib/active_admin_import/model.rb', line 58 def read_attribute_for_validation(key) @attributes[key.to_sym] end |