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

pulibrary / oawaiver / 11c952aa-d8e8-4073-941a-ba08eee9b0bb

24 Sep 2024 03:41PM UTC coverage: 70.281% (-28.5%) from 98.795%
11c952aa-d8e8-4073-941a-ba08eee9b0bb

push

circleci

jrgriffiniii
wip

525 of 747 relevant lines covered (70.28%)

9.14 hits per line

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

98.55
/app/lib/author_status.rb
1
# frozen_string_literal: true
2

3
require "uri"
1✔
4

5
class AuthorStatus
1✔
6
  @status_faculty = nil
1✔
7
  @status_other = nil
1✔
8

9
  @ajax_info = []
1✔
10

11
  @ajax_path = nil
1✔
12
  @ajax_match_params = nil
1✔
13
  @status_path = nil
1✔
14

15
  @unique_id_urls = {}
1✔
16

17
  DEFAULT_STATUS = "non faculty"
1✔
18
  FACULTY_STATUS = "faculty"
1✔
19
  UNKNOWN_STATUS = "unknown"
1✔
20

21
  class << self
1✔
22
    attr_reader :current_config, :get_unique_id_path, :unique_id_urls
1✔
23
    attr_writer :base_url
1✔
24
  end
25

26
  def self.build_base_url(context: nil)
1✔
27
    if context&.respond_to?(:request)
4✔
28
      request = context.request
3✔
29
      "#{request.protocol}#{request.host_with_port}#{@base_url}"
3✔
30
    else
31
      @base_url
1✔
32
    end
33
  end
34

35
  def self.bootstrap(opts)
1✔
36
    return if current_config
2✔
37

38
    @status_other = DEFAULT_STATUS
1✔
39
    @status_faculty = FACULTY_STATUS
1✔
40
    @status_unknonw = UNKNOWN_STATUS
1✔
41

42
    @current_config = opts[Rails.env]
1✔
43
    @base_url = current_config.fetch("base_url", "")
1✔
44

45
    @ajax_path = current_config["ajax_path"]
1✔
46
    config_ajax_params = current_config["ajax_params"]
1✔
47
    @ajax_match_params = config_ajax_params
1✔
48

49
    @status_path = current_config["status_path"]
1✔
50
    @get_unique_id_path = current_config["get_unique_id_path"]
1✔
51
    return if @base_url.blank?
1✔
52

53
    %w[html json].each do |format|
1✔
54
      raise("Missing the AuthorStatus '#{format}' configuration entry for :get_unique_id_path.") unless get_unique_id_path.key?(format)
2✔
55
    end
56
  end
57

58
  # Bootstrap the AuthorStatus class with the configuration from the given file.
59
  #
60
  # @param file_path [String] the path to the configuration file
61
  # @return [void]
62
  def self.build_from_config(file_path:)
1✔
63
    config = YAML.load_file(file_path)
2✔
64
    bootstrap(config)
2✔
65
  end
66

67
  def self.status_faculty
1✔
68
    FACULTY_STATUS
86✔
69
  end
70

71
  def self.faculty_status?(status)
1✔
72
    status_faculty == status
83✔
73
  end
74

75
  def self.status_other
1✔
76
    DEFAULT_STATUS
2✔
77
  end
78

79
  def self.status_list
1✔
80
    [
81
      FACULTY_STATUS,
×
82
      DEFAULT_STATUS,
83
      UNKNOWN_STATUS
84
    ]
85
  end
86

87
  def self.safe_ajax_path
1✔
88
    @ajax_path.html_safe
2✔
89
  end
90

91
  def self.ajax_url(context: nil)
1✔
92
    base_url = build_base_url(context: context)
1✔
93

94
    safe_ajax_path = @ajax_path.html_safe
1✔
95
    segments = [
96
      base_url,
1✔
97
      safe_ajax_path
98
    ]
99

100
    segments.join("/")
1✔
101
  end
102

103
  def self.safe_ajax_params
1✔
104
    @ajax_match_params.html_safe
1✔
105
  end
106

107
  def self.ajax_params
1✔
108
    safe_ajax_params
1✔
109
  end
110

111
  def self.status_url(context: nil)
1✔
112
    base_url = build_base_url(context: context)
2✔
113

114
    segments = [
115
      base_url,
2✔
116
      safe_ajax_path
117
    ]
118

119
    segments.join("/")
2✔
120
  end
121

122
  def self.generate_uid_url(uid, format = "html", context: nil)
1✔
123
    escaped_uid = Rack::Utils.escape(uid)
1✔
124
    unique_id_path = get_unique_id_path[format]
1✔
125
    uid_path = unique_id_path.gsub(/MATCH/, escaped_uid)
1✔
126
    safe_uid_path = uid_path.html_safe
1✔
127

128
    base_url = build_base_url(context: context)
1✔
129

130
    segments = [
131
      base_url,
1✔
132
      safe_uid_path
133
    ]
134

135
    segments.join("/")
1✔
136
  end
137
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc