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

pulibrary / oawaiver / 78018399-b378-4ad5-bd31-e44fc8de7c31

23 May 2024 05:45PM UTC coverage: 80.213% (+0.07%) from 80.142%
78018399-b378-4ad5-bd31-e44fc8de7c31

Pull #169

circleci

bess
Use attr reader to replace method
Pull Request #169: Refactor: Move lib inside rails app

5 of 6 new or added lines in 1 file covered. (83.33%)

677 of 844 relevant lines covered (80.21%)

17.16 hits per line

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

76.62
/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 :unique_id_urls
1✔
23
  end
24

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

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

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

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

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

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

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

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

66
  def base_uri
1✔
67
    URI(@base_url)
×
68
  end
69

70
  def ajax_uri
1✔
71
    URI(ajax_url)
×
72
  end
73

74
  def status_uri
1✔
75
    URI(status_url)
×
76
  end
77

78
  def self.status_faculty
1✔
79
    FACULTY_STATUS
67✔
80
  end
81

82
  def self.faculty_status?(status)
1✔
83
    status_faculty == status
65✔
84
  end
85

86
  def self.status_other
1✔
87
    DEFAULT_STATUS
1✔
88
  end
89

90
  def self.status_list
1✔
91
    [
92
      FACULTY_STATUS,
×
93
      DEFAULT_STATUS,
94
      UNKNOWN_STATUS
95
    ]
96
  end
97

98
  def self.safe_ajax_path
1✔
99
    @ajax_path.html_safe
2✔
100
  end
101

102
  def self.ajax_url(context: nil)
1✔
103
    base_url = build_base_url(context: context)
×
104

105
    safe_ajax_path = @ajax_path.html_safe
×
106
    segments = [
107
      base_url,
×
108
      safe_ajax_path
109
    ]
110

111
    segments.join("/")
×
112
  end
113

114
  def self.safe_ajax_params
1✔
115
    @ajax_match_params.html_safe
×
116
  end
117

118
  def self.ajax_params
1✔
119
    safe_ajax_params
×
120
  end
121

122
  def self.status_url(context: nil)
1✔
123
    base_url = build_base_url(context: context)
2✔
124

125
    segments = [
126
      base_url,
2✔
127
      safe_ajax_path
128
    ]
129

130
    segments.join("/")
2✔
131
  end
132

133
  def self.generate_uid_url(uid, format = "html", context: nil)
1✔
134
    escaped_uid = Rack::Utils.escape(uid)
×
NEW
135
    unique_id_path = get_unique_id_path[format]
×
136
    uid_path = unique_id_path.gsub(/MATCH/, escaped_uid)
×
137
    safe_uid_path = uid_path.html_safe
×
138

139
    base_url = build_base_url(context: context)
×
140

141
    segments = [
142
      base_url,
×
143
      safe_uid_path
144
    ]
145

146
    segments.join("/")
×
147
  end
148

149
  class << self
1✔
150
    attr_reader :current_config, :get_unique_id_path
1✔
151
    attr_writer :base_url
1✔
152
  end
153
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