Class: OptAR::OAR
- Inherits:
-
Object
- Object
- OptAR::OAR
- Includes:
- MethodFinderHelper
- Defined in:
- lib/opt_ar/oar.rb
Overview
Dupe of ActiveRecord::Base providing necessary read functionalities
of it, while removing a lot of abstactions that it provides
to reduce memory and processing time utilisation
attributes : contains the requested attributes from AR klass_name : class name of original AR model klass_object : original AR object loaded
Constant Summary collapse
- BLACKLISTED_ATTRIBUTES =
'BLACKLISTED_ATTRIBUTES'.freeze
Constants included from MethodFinderHelper
MethodFinderHelper::DATE_TIME_CONST_KEY, MethodFinderHelper::DEFAULT_DATE_TIME_ATTRIBUTES, MethodFinderHelper::ID_STRING, MethodFinderHelper::WARN_MSG
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#klass_name ⇒ Object
readonly
Returns the value of attribute klass_name.
-
#klass_object ⇒ Object
readonly
Returns the value of attribute klass_object.
Class Method Summary collapse
-
.from_json(string) ⇒ Object
TODO: for handling JSON serialization.
- .init_manual(attrs, klass, req_attributes) ⇒ Object
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(object, options = {}) ⇒ OAR
constructor
A new instance of OAR.
- #to_json ⇒ Object
Constructor Details
#initialize(object, options = {}) ⇒ OAR
Returns a new instance of OAR.
18 19 20 21 22 23 |
# File 'lib/opt_ar/oar.rb', line 18 def initialize(object, = {}) req_attributes = [:attrs] || [] assign_attributes(object, req_attributes) @klass_name = object.class.name # define_attr_readers end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OptAR::MethodFinderHelper
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
14 15 16 |
# File 'lib/opt_ar/oar.rb', line 14 def attributes @attributes end |
#klass_name ⇒ Object (readonly)
Returns the value of attribute klass_name.
14 15 16 |
# File 'lib/opt_ar/oar.rb', line 14 def klass_name @klass_name end |
#klass_object ⇒ Object (readonly)
Returns the value of attribute klass_object.
14 15 16 |
# File 'lib/opt_ar/oar.rb', line 14 def klass_object @klass_object end |
Class Method Details
.from_json(string) ⇒ Object
TODO: for handling JSON serialization
46 |
# File 'lib/opt_ar/oar.rb', line 46 def self.from_json(string); end |
.init_manual(attrs, klass, req_attributes) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/opt_ar/oar.rb', line 25 def self.init_manual(attrs, klass, req_attributes) oar = allocate attr_keys = oar.send(:fetch_attribute_keys, req_attributes, klass) attrs = attrs.slice(*attr_keys) oar.instance_variable_set('@attributes', attrs) oar.instance_variable_set('@klass_name', klass.name) oar.send(:transform_datetime_attributes, klass) oar end |
Instance Method Details
#as_json ⇒ Object
35 36 37 38 39 |
# File 'lib/opt_ar/oar.rb', line 35 def as_json { klass_key => attributes.as_json } end |
#to_json ⇒ Object
41 42 43 |
# File 'lib/opt_ar/oar.rb', line 41 def to_json JSON.dump(as_json) end |