Module: DecoLite::FieldCreatable
- Includes:
- FieldConflictable, FieldValidatable
- Included in:
- HashLoadable
- Defined in:
- lib/deco_lite/field_creatable.rb
Overview
Takes an array of symbols and creates attr_accessors.
Constant Summary
Constants included from FieldValidatable
DecoLite::FieldValidatable::FIELD_NAME_REGEX
Constants included from FieldsOptionable
DecoLite::FieldsOptionable::OPTION_FIELDS, DecoLite::FieldsOptionable::OPTION_FIELDS_DEFAULT, DecoLite::FieldsOptionable::OPTION_FIELDS_MERGE, DecoLite::FieldsOptionable::OPTION_FIELDS_STRICT, DecoLite::FieldsOptionable::OPTION_FIELDS_VALUES
Instance Method Summary collapse
- #create_field_accessor(field_name:, options:) ⇒ Object
- #create_field_accessors(field_names:, options:) ⇒ Object
Methods included from FieldValidatable
Methods included from FieldConflictable
#attr_accessor_exist?, #field_conflict?, #field_names_include?, #validate_field_conflicts!
Methods included from FieldNameNamespaceable
#field_name_or_field_name_with_namespace, #field_name_with_namespace
Instance Method Details
#create_field_accessor(field_name:, options:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/deco_lite/field_creatable.rb', line 20 def create_field_accessor(field_name:, options:) validate_field_name!(field_name:, options:) validate_field_conflicts!(field_name:, options:) # If we want to set a class-level attr_accessor # self.class.attr_accessor(field_name) if field_name.present? create_field_getter(field_name:, options:) create_field_setter field_name:, options: end |
#create_field_accessors(field_names:, options:) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/deco_lite/field_creatable.rb', line 12 def create_field_accessors(field_names:, options:) return if field_names.blank? field_names.each do |field_name| create_field_accessor(field_name:, options:) end end |