Module: JSONAPIonify::Api::Resource::ClassMethods
- Included in:
- JSONAPIonify::Api::Resource
- Defined in:
- lib/jsonapionify/api/resource/class_methods.rb
Class Method Summary collapse
Instance Method Summary collapse
- #api ⇒ Object
- #cache(store, *args) ⇒ Object
- #cache_store ⇒ Object
- #cache_store=(store) ⇒ Object
- #default_strategy ⇒ Object
- #description(description) ⇒ Object
- #eager_load ⇒ Object
- #get_url(base) ⇒ Object
- #set_api(api) ⇒ Object
- #set_type(type) ⇒ Object
- #type ⇒ Object
Class Method Details
.extended(klass) ⇒ Object
6 7 8 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 6 def self.extended(klass) klass.include ActiveSupport::Rescuable end |
Instance Method Details
#api ⇒ Object
35 36 37 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 35 def api nil end |
#cache(store, *args) ⇒ Object
53 54 55 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 53 def cache(store, *args) self.cache_store = ActiveSupport::Cache.lookup_store(store, *args) end |
#cache_store ⇒ Object
61 62 63 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 61 def cache_store @cache_store ||= api.cache_store end |
#cache_store=(store) ⇒ Object
57 58 59 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 57 def cache_store=(store) @cache_store = store end |
#default_strategy ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 65 def default_strategy if defined?(ActiveRecord) && current_scope.is_a?(Class) && current_scope < ActiveRecord::Base :active_record elsif Enumerable === current_scope || (current_scope.is_a?(Class) && current_scope < Enumerable) :enumerable end rescue NotImplementedError nil end |
#description(description) ⇒ Object
10 11 12 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 10 def description(description) @description = description end |
#eager_load ⇒ Object
39 40 41 42 43 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 39 def eager_load relationships.map(&:name).each do |name| relationship name end end |
#get_url(base) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 45 def get_url(base) URI.parse(base).tap do |uri| uri.path = File.join(uri.path, type) params = sticky_params(Rack::Utils.parse_nested_query(uri.query)) uri.query = params.to_param if params.present? end.to_s end |
#set_api(api) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 14 def set_api(api) self.tap do define_singleton_method :api do api end end end |
#set_type(type) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 22 def set_type(type) type = type.to_s self.tap do define_singleton_method :type do type end end end |
#type ⇒ Object
31 32 33 |
# File 'lib/jsonapionify/api/resource/class_methods.rb', line 31 def type nil end |