Module: ArtirixDataModels::DAO
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/artirix_data_models/dao.rb
Defined Under Namespace
Modules: FakeModes
Constant Summary collapse
- DELEGATED_METHODS =
[ :partial_mode_fields, :model_name, :model_class, :paths_factory, :fake_mode_factory, :gateway, :force_fake_enabled, :force_fake_disabled, :remove_force_fake, :fake?, :forced_fake_enabled?, :forced_fake_disabled?, :empty_collection, :empty_collection_for, :perform_get, :perform_post, :perform_put, :perform_delete, ]
Instance Method Summary collapse
- #default_fake_mode_factory ⇒ Object
- #default_model_class ⇒ Object
- #default_model_name ⇒ Object
- #default_path_factory ⇒ Object
- #find(model_pk, cache_adaptor: nil, **extra_options) ⇒ Object
- #get(model_pk, cache_adaptor: nil, **extra_options) ⇒ Object
- #get_full(model_pk, model_to_reload: nil, cache_adaptor: nil, **extra_options) ⇒ Object
- #get_some(model_pks, cache_adaptor: nil, **extra_options) ⇒ Object
- #in_fake_mode ⇒ Object
- #initialize(gateway: nil, gateway_factory: nil, ignore_default_gateway: false, model_name: nil, model_class: nil, paths_factory: nil, fake_mode_factory: nil) ⇒ Object
-
#reload(model) ⇒ Object
DELEGATE TO BASIC_MODEL_DAO #.
Instance Method Details
#default_fake_mode_factory ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/artirix_data_models/dao.rb', line 63 def default_fake_mode_factory if defined?(self.class::FakeMode) self.class::FakeMode else FakeModes::Disabled end end |
#default_model_class ⇒ Object
55 56 57 |
# File 'lib/artirix_data_models/dao.rb', line 55 def default_model_class defined?(self.class::MODEL_CLASS) ? self.class::MODEL_CLASS : nil end |
#default_model_name ⇒ Object
51 52 53 |
# File 'lib/artirix_data_models/dao.rb', line 51 def default_model_name defined?(self.class::MODEL_NAME) ? self.class::MODEL_NAME : nil end |
#default_path_factory ⇒ Object
59 60 61 |
# File 'lib/artirix_data_models/dao.rb', line 59 def default_path_factory self.class::Paths end |
#find(model_pk, cache_adaptor: nil, **extra_options) ⇒ Object
101 102 103 104 |
# File 'lib/artirix_data_models/dao.rb', line 101 def find(model_pk, cache_adaptor: nil, **) cache_adaptor ||= cache_model_adaptor_for_find(model_pk, **) basic_model_dao.find(model_pk, cache_adaptor: cache_adaptor, **) end |
#get(model_pk, cache_adaptor: nil, **extra_options) ⇒ Object
96 97 98 99 |
# File 'lib/artirix_data_models/dao.rb', line 96 def get(model_pk, cache_adaptor: nil, **) cache_adaptor ||= cache_model_adaptor_for_get(model_pk, **) basic_model_dao.get(model_pk, cache_adaptor: cache_adaptor, **) end |
#get_full(model_pk, model_to_reload: nil, cache_adaptor: nil, **extra_options) ⇒ Object
90 91 92 93 94 |
# File 'lib/artirix_data_models/dao.rb', line 90 def get_full(model_pk, model_to_reload: nil, cache_adaptor: nil, **) model_to_reload ||= new_model_with_pk(model_pk) cache_adaptor ||= cache_model_adaptor_for_get_full(model_pk, model_to_reload: model_to_reload, **) basic_model_dao.get_full(model_pk, model_to_reload: model_to_reload, cache_adaptor: cache_adaptor, **) end |
#get_some(model_pks, cache_adaptor: nil, **extra_options) ⇒ Object
106 107 108 109 |
# File 'lib/artirix_data_models/dao.rb', line 106 def get_some(model_pks, cache_adaptor: nil, **) cache_adaptor ||= cache_model_adaptor_for_get_some(model_pks, **) basic_model_dao.get_some(model_pks, cache_adaptor: cache_adaptor, **) end |
#in_fake_mode ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/artirix_data_models/dao.rb', line 71 def in_fake_mode return unless block_given? begin basic_model_dao.force_fake_enabled yield ensure basic_model_dao.remove_force_fake end end |
#initialize(gateway: nil, gateway_factory: nil, ignore_default_gateway: false, model_name: nil, model_class: nil, paths_factory: nil, fake_mode_factory: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/artirix_data_models/dao.rb', line 34 def initialize(gateway: nil, gateway_factory: nil, ignore_default_gateway: false, model_name: nil, model_class: nil, paths_factory: nil, fake_mode_factory: nil) if gateway.blank? && gateway_factory.blank? && !ignore_default_gateway gateway = ArtirixDataModels::DAORegistry.gateway end model_name ||= default_model_name model_class ||= default_model_class paths_factory ||= default_path_factory fake_mode_factory ||= default_fake_mode_factory @basic_model_dao = ArtirixDataModels::DAORegistry.basic_class.new model_name: model_name, model_class: model_class, fake_mode_factory: fake_mode_factory, paths_factory: paths_factory, gateway: gateway, gateway_factory: gateway_factory end |
#reload(model) ⇒ Object
DELEGATE TO BASIC_MODEL_DAO #
86 87 88 |
# File 'lib/artirix_data_models/dao.rb', line 86 def reload(model) get_full model.primary_key, model_to_reload: model end |