Class: JSONAPIonify::Api::Resource
- Inherits:
-
Object
- Object
- JSONAPIonify::Api::Resource
- Extended by:
- ClassMethods, Definitions, Documentation, JSONAPIonify::Autoload
- Includes:
- Builders, Defaults, ErrorHandling, Includer, Callbacks
- Defined in:
- lib/jsonapionify/api/resource.rb
Defined Under Namespace
Modules: Builders, Caching, Callbacks, Caller, ClassMethods, Defaults, Definitions, Documentation, ErrorHandling, Exec, Includer
Constant Summary
Constants included from Builders
Builders::FALSEY_STRINGS, Builders::TRUTHY_STRINGS
Constants included from Structure
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#response_headers ⇒ Object
readonly
Returns the value of attribute response_headers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(request:, context_definitions: self.class.context_definitions, commit: true, callbacks: true, context_overrides: {}, cacheable: true, action: nil) ⇒ Resource
constructor
A new instance of Resource.
Methods included from JSONAPIonify::Autoload
autoload_all, eager_load!, unloaded
Methods included from ClassMethods
api, cache, cache_store, cache_store=, default_strategy, description, eager_load, extended, get_url, set_api, set_type, type
Methods included from Definitions
Methods included from Documentation
documentation_object, documented_actions_in_order, example_id_generator, example_instance_for_action, extended
Methods included from Defaults
Methods included from Includer
#append_included, #fetch_included, includes_to_hashes
Methods included from ErrorHandling
#error, #error_meta, #error_now, #halt, #set_errors
Methods included from Callbacks
Constructor Details
#initialize(request:, context_definitions: self.class.context_definitions, commit: true, callbacks: true, context_overrides: {}, cacheable: true, action: nil) ⇒ Resource
Returns a new instance of Resource.
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 |
# File 'lib/jsonapionify/api/resource.rb', line 39 def initialize( request:, context_definitions: self.class.context_definitions, commit: true, callbacks: true, context_overrides: {}, cacheable: true, action: nil ) context_overrides[:action_name] ||= action.name if action @__context = ContextDelegate.new( request, self, context_definitions, context_overrides ) @errors = @__context.errors @action = action @response_headers = @__context.response_headers @callbacks = action ? callbacks : false @cache_options = {} extend Caller if commit && action extend Exec unless action extend Caching if cacheable end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
37 38 39 |
# File 'lib/jsonapionify/api/resource.rb', line 37 def action @action end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
37 38 39 |
# File 'lib/jsonapionify/api/resource.rb', line 37 def errors @errors end |
#response_headers ⇒ Object (readonly)
Returns the value of attribute response_headers.
37 38 39 |
# File 'lib/jsonapionify/api/resource.rb', line 37 def response_headers @response_headers end |
Class Method Details
.cache_key(**options) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/jsonapionify/api/resource.rb', line 30 def self.cache_key(**) api.cache_key( **, resource: name ) end |
.inherited(subclass) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/jsonapionify/api/resource.rb', line 22 def self.inherited(subclass) super(subclass) subclass.class_eval do context(:api, readonly: true, persisted: true) { self.class.api } context(:resource, readonly: true, persisted: true) { self } end end |