Class: ArtirixDataModels::ActiveNull::NullModelBuilder
- Inherits:
-
Object
- Object
- ArtirixDataModels::ActiveNull::NullModelBuilder
- Defined in:
- lib/artirix_data_models/active_null.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#overrides ⇒ Object
readonly
Returns the value of attribute overrides.
Instance Method Summary collapse
- #build ⇒ Object
- #full_name ⇒ Object
-
#initialize(model, overrides) ⇒ NullModelBuilder
constructor
A new instance of NullModelBuilder.
- #name ⇒ Object
- #set_null_model(null) ⇒ Object
Constructor Details
#initialize(model, overrides) ⇒ NullModelBuilder
Returns a new instance of NullModelBuilder.
21 22 23 24 |
# File 'lib/artirix_data_models/active_null.rb', line 21 def initialize(model, overrides) @model = model @overrides = overrides end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
19 20 21 |
# File 'lib/artirix_data_models/active_null.rb', line 19 def model @model end |
#overrides ⇒ Object (readonly)
Returns the value of attribute overrides.
19 20 21 |
# File 'lib/artirix_data_models/active_null.rb', line 19 def overrides @overrides end |
Instance Method Details
#build ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/artirix_data_models/active_null.rb', line 26 def build model = self.model null = Naught.build do |config| config.impersonate model config.predicates_return false def nil? true end def present? false end def blank? true end def to_json '{}' end ########################## # ACTIVE MODEL COMPLIANT # ########################## def to_model self end def to_partial_path model._to_partial_path end def persisted? true end def valid? true end def new_record? false end def destroyed? false end def errors obj = Object.new def obj.[](key) [] end def obj.() [] end obj end ########## # DRAPER # ########## if Object.const_defined? 'Draper' def decorate( = {}) decorator_class.decorate(self, ) end def decorator_class self.class.decorator_class end def decorator_class? self.class.decorator_class? end def applied_decorators [] end def decorated_with?(decorator_class) false end def decorated? false end end end null.send(:include, Draper::Decoratable) if Object.const_defined? 'Draper' null.send(:include, overrides) if overrides null.send(:include, ArtirixDataModels::Model::ActiveModelCompliant) set_null_model null end |
#full_name ⇒ Object
132 133 134 135 |
# File 'lib/artirix_data_models/active_null.rb', line 132 def full_name return name if model.parent == Object "#{model.parent.name}::#{name}" end |
#name ⇒ Object
127 128 129 130 |
# File 'lib/artirix_data_models/active_null.rb', line 127 def name base_name = model.name.split('::').last "Null#{base_name}" end |
#set_null_model(null) ⇒ Object
137 138 139 |
# File 'lib/artirix_data_models/active_null.rb', line 137 def set_null_model(null) model.parent.const_set name, null end |