• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

praxis / praxis / #764

17 Jul 2023 04:35PM UTC coverage: 39.085% (-21.2%) from 60.271%
#764

push

coveralls-ruby

web-flow
check default_for_null to expose it as nullable if that's the default behavior, regardless of no null: key passed in in an attribute (#396)

Co-authored-by: Josep M. Blanquer <blanquer@C02F20XQMD6W.local>

1359 of 3477 relevant lines covered (39.09%)

0.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/lib/praxis/plugins/mapper_plugin.rb
1
# frozen_string_literal: true
2

3
require 'singleton'
1✔
4

5
require 'praxis/extensions/field_selection'
1✔
6

7
module Praxis
1✔
8
  module Plugins
1✔
9
    module MapperPlugin
1✔
10
      include Praxis::PluginConcern
1✔
11

12
      # The Mapper plugin is an overarching set of things to include in your application
13
      # when you want to use the rendring, field_selection, filtering (and potentially pagination) extensions
14
      # To use the plugin, set it up like any other plugin by registering to the bootloader.
15
      # Typically you'd do that in environment.rb, inside the `Praxis::Application.configure do |application|` block, by:
16
      #   application.bootloader.use Praxis::Plugins::MapperPlugin
17
      #
18
      # The plugin accepts only 1 configuration option thus far, which you can set inside the same block as:
19
      #   application.config.mapper.debug_queries = true
20
      # when debug_queries is set to true, the system will output information about the expanded fields
21
      # and associations that the system ihas calculated necessary to pull from the DB, based on the requested
22
      # API fields, API filters and `property` dependencies defined in the domain models (i.e., resources)
23
      class Plugin < Praxis::Plugin
1✔
24
        include Singleton
1✔
25

26
        def config_key
1✔
27
          :mapper
×
28
        end
29

30
        def load_config!
1✔
31
          {} # override the default one, since we don't necessarily want to configure it via a yaml file.
×
32
        end
33

34
        def prepare_config!(node)
1✔
35
          node.attributes do
×
36
            attribute :debug_queries, Attributor::Boolean, default: false,
×
37
                                                           description: 'Weather or not to log debug information about queries executed in the build_query automation module'
38
          end
39
        end
40
      end
41

42
      module Controller
1✔
43
        extend ActiveSupport::Concern
1✔
44

45
        included do
1✔
46
          include Praxis::Extensions::Rendering
×
47
          include Praxis::Extensions::FieldExpansion
×
48
        end
49

50
        def build_query(base_query)
1✔
51
          domain_model = media_type&.domain_model
×
52
          raise "No domain model defined for #{name}. Cannot use the attribute filtering helpers without it" unless domain_model
×
53

54
          filters = request.params.filters if request.params.respond_to?(:filters)
×
55
          # Handle filters
56
          base_query = domain_model.craft_filter_query(base_query, filters: filters)
×
57

58
          selectors = selector_generator.selectors
×
59
          base_query = domain_model.craft_field_selection_query(base_query, selectors: selectors)
×
60
          # handle pagination and ordering if the pagination extention is included
61
          base_query = domain_model.craft_pagination_query(base_query, pagination: _pagination, selectors: selectors) if respond_to?(:_pagination)
×
62

63
          base_query
×
64
        end
65

66
        def selector_generator
1✔
67
          return unless media_type.respond_to?(:domain_model) &&
×
68
                        media_type.domain_model < Praxis::Mapper::Resource
69

70
          @selector_generator ||= \
×
71
            Praxis::Mapper::SelectorGenerator.new.add(media_type.domain_model, expanded_fields)
72
        end
73
      end
74
    end
75
  end
76
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc