Module: IntrospectiveGrape::Helpers
- Included in:
- API
- Defined in:
- lib/introspective_grape/helpers.rb
Constant Summary collapse
- API_ACTIONS =
[:index,:show,:create,:update,:destroy].freeze
Instance Method Summary collapse
- #authentication_method(context) ⇒ Object
- #authentication_method=(method) ⇒ Object
- #default_includes(model, *args) ⇒ Object
- #exclude_actions(model, *args) ⇒ Object
- #include_actions(model, *args) ⇒ Object
- #paginate(args = {}) ⇒ Object
- #pagination ⇒ Object
- #skip_presence_validations(fields = nil) ⇒ Object
- #whitelist(whitelist = nil) ⇒ Object
Instance Method Details
#authentication_method(context) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/introspective_grape/helpers.rb', line 8 def authentication_method(context) # Default to "authenticate!" or as grape docs once suggested, "authorize!" if @authentication_method @authentication_method elsif context.respond_to?('authenticate!') 'authenticate!' elsif context.respond_to?('authorize!') 'authorize!' end end |
#authentication_method=(method) ⇒ Object
3 4 5 6 |
# File 'lib/introspective_grape/helpers.rb', line 3 def authentication_method=(method) # IntrospectiveGrape::API.authentication_method= @authentication_method = method end |
#default_includes(model, *args) ⇒ Object
45 46 47 48 |
# File 'lib/introspective_grape/helpers.rb', line 45 def default_includes(model, *args) @default_includes ||= {} @default_includes[model.name] = args.present? ? args.flatten : @default_includes[model.name] || [] end |
#exclude_actions(model, *args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/introspective_grape/helpers.rb', line 27 def exclude_actions(model, *args) @exclude_actions ||= {}; @exclude_actions[model.name] ||= [] args.flatten! args = API_ACTIONS if args.include?(:all) args = [] if args.include?(:none) undefined_actions = args.compact-API_ACTIONS raise "#{model.name} defines invalid actions: #{undefined_actions}" if undefined_actions.present? @exclude_actions[model.name] = args.present? ? args.compact : @exclude_actions[model.name] || [] end |
#include_actions(model, *args) ⇒ Object
39 40 41 42 |
# File 'lib/introspective_grape/helpers.rb', line 39 def include_actions(model, *args) @exclude_actions ||= {}; @exclude_actions[model.name] ||= [] @exclude_actions[model.name] = API_ACTIONS-exclude_actions(model, args) end |
#paginate(args = {}) ⇒ Object
19 20 21 |
# File 'lib/introspective_grape/helpers.rb', line 19 def paginate(args={}) @pagination = args end |
#pagination ⇒ Object
23 24 25 |
# File 'lib/introspective_grape/helpers.rb', line 23 def pagination @pagination end |
#skip_presence_validations(fields = nil) ⇒ Object
55 56 57 58 |
# File 'lib/introspective_grape/helpers.rb', line 55 def skip_presence_validations(fields=nil) return @skip_presence_fields||[] if !fields @skip_presence_fields = [fields].flatten end |
#whitelist(whitelist = nil) ⇒ Object
50 51 52 53 |
# File 'lib/introspective_grape/helpers.rb', line 50 def whitelist(whitelist=nil) return @whitelist if !whitelist @whitelist = whitelist end |