Class: DecoLite::Model
- Inherits:
-
Object
- Object
- DecoLite::Model
- Includes:
- ActiveModel::Model, FieldRequireable, HashLoadable, Hashable, ModelNameable, Optionable
- Defined in:
- lib/deco_lite/model.rb
Overview
This class defines the base class for classes that create dynamic models that can be used as decorators.
Constant Summary
Constants included from OptionsValidatable
Constants included from NamespaceOptionable
NamespaceOptionable::OPTION_NAMESPACE, NamespaceOptionable::OPTION_NAMESPACE_DEFAULT
Constants included from FieldsOptionable
FieldsOptionable::OPTION_FIELDS, FieldsOptionable::OPTION_FIELDS_DEFAULT, FieldsOptionable::OPTION_FIELDS_MERGE, FieldsOptionable::OPTION_FIELDS_STRICT, FieldsOptionable::OPTION_FIELDS_VALUES
Instance Attribute Summary
Attributes included from FieldInformable
Instance Method Summary collapse
-
#initialize(options: {}) ⇒ Model
constructor
A new instance of Model.
- #load(hash:, options: {}) ⇒ Object
Methods included from Optionable
Methods included from OptionsValidatable
#validate_option_fields!, #validate_option_keys!, #validate_option_namespace!, #validate_options!, #validate_options_present!
Methods included from ModelNameable
Methods included from FieldInformable
#field_names, get_field_info, merge_field_info!, set_field_info!
Methods included from FieldAssignable
#set_field_value, #set_field_values
Methods included from FieldRetrievable
Methods included from FieldCreatable
#create_field_accessor, #create_field_accessors
Methods included from FieldConflictable
#field_conflict?, #validate_field_conflicts!
Methods included from Hashable
Methods included from FieldRequireable
#required_field_exist?, #required_fields, #validate_required_fields
Constructor Details
#initialize(options: {}) ⇒ Model
Returns a new instance of Model.
23 24 25 26 27 28 29 30 31 |
# File 'lib/deco_lite/model.rb', line 23 def initialize(options: {}) @field_info = {} # Accept whatever options are sent, but make sure # we have defaults set up. #options_with_defaults # will merge options into OptionsDefaultable::DEFAULT_OPTIONS # so we have defaults for any options not passed in through # options. self. = Options.with_defaults end |
Instance Method Details
#load(hash:, options: {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/deco_lite/model.rb', line 33 def load(hash:, options: {}) # Merge options into the default options passed through the # constructor; these will override any options passed in when # this object was created, allowing us to retain any defaut # options while loading, but also provide option customization # of options when needed. = Options.with_defaults(, defaults: self.) load_hash(hash: hash, options: ) self end |