Class: Jason::ApiModel
- Inherits:
-
Object
- Object
- Jason::ApiModel
- Defined in:
- lib/jason/api_model.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_object_params ⇒ Object
- #allowed_params ⇒ Object
- #as_json_config ⇒ Object
- #include_methods ⇒ Object
-
#initialize(name) ⇒ ApiModel
constructor
A new instance of ApiModel.
- #permit(params) ⇒ Object
- #priority_scope ⇒ Object
- #scope ⇒ Object
- #subscribed_fields ⇒ Object
Constructor Details
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
3 4 5 |
# File 'lib/jason/api_model.rb', line 3 def model @model end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/jason/api_model.rb', line 3 def name @name end |
Class Method Details
.configure(models) ⇒ Object
5 6 7 |
# File 'lib/jason/api_model.rb', line 5 def self.configure(models) @@models = models end |
Instance Method Details
#allowed_object_params ⇒ Object
18 19 20 |
# File 'lib/jason/api_model.rb', line 18 def allowed_object_params model.allowed_object_params || [] end |
#allowed_params ⇒ Object
14 15 16 |
# File 'lib/jason/api_model.rb', line 14 def allowed_params model.allowed_params || [] end |
#as_json_config ⇒ Object
46 47 48 |
# File 'lib/jason/api_model.rb', line 46 def as_json_config { only: subscribed_fields, methods: include_methods } end |
#include_methods ⇒ Object
22 23 24 |
# File 'lib/jason/api_model.rb', line 22 def include_methods model.include_methods || [] end |
#permit(params) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/jason/api_model.rb', line 38 def permit(params) params = params.require(:payload).permit(allowed_params).tap do |allowed| allowed_object_params.each do |key| allowed[key] = params[:payload][key].to_unsafe_h if params[:payload][key] end end end |
#priority_scope ⇒ Object
26 27 28 |
# File 'lib/jason/api_model.rb', line 26 def priority_scope model.priority_scope || [] end |
#scope ⇒ Object
34 35 36 |
# File 'lib/jason/api_model.rb', line 34 def scope model.scope end |
#subscribed_fields ⇒ Object
30 31 32 |
# File 'lib/jason/api_model.rb', line 30 def subscribed_fields model.subscribed_fields || [] end |