Class: Steep::Server::TypeCheckController::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/server/type_check_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guid:, progress:) ⇒ Request

Returns a new instance of Request.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/steep/server/type_check_controller.rb', line 17

def initialize(guid:, progress:)
  @guid = guid
  @library_paths = Set[]
  @signature_paths = Set[]
  @code_paths = Set[]
  @inline_paths = Set[]
  @priority_paths = Set[]
  @checked_paths = Set[]
  @work_done_progress = progress
  @started_at = Time.now
  @needs_response = false
  @report_progress = false
end

Instance Attribute Details

#checked_pathsObject (readonly)

Returns the value of attribute checked_paths.



11
12
13
# File 'lib/steep/server/type_check_controller.rb', line 11

def checked_paths
  @checked_paths
end

#code_pathsObject (readonly)

Returns the value of attribute code_paths.



8
9
10
# File 'lib/steep/server/type_check_controller.rb', line 8

def code_paths
  @code_paths
end

#guidObject (readonly)

Returns the value of attribute guid.



5
6
7
# File 'lib/steep/server/type_check_controller.rb', line 5

def guid
  @guid
end

#inline_pathsObject (readonly)

Returns the value of attribute inline_paths.



9
10
11
# File 'lib/steep/server/type_check_controller.rb', line 9

def inline_paths
  @inline_paths
end

#library_pathsObject (readonly)

Returns the value of attribute library_paths.



6
7
8
# File 'lib/steep/server/type_check_controller.rb', line 6

def library_paths
  @library_paths
end

#needs_responseObject

Returns the value of attribute needs_response.



14
15
16
# File 'lib/steep/server/type_check_controller.rb', line 14

def needs_response
  @needs_response
end

#priority_pathsObject (readonly)

Returns the value of attribute priority_paths.



10
11
12
# File 'lib/steep/server/type_check_controller.rb', line 10

def priority_paths
  @priority_paths
end

#report_progressObject (readonly)

Returns the value of attribute report_progress.



15
16
17
# File 'lib/steep/server/type_check_controller.rb', line 15

def report_progress
  @report_progress
end

#signature_pathsObject (readonly)

Returns the value of attribute signature_paths.



7
8
9
# File 'lib/steep/server/type_check_controller.rb', line 7

def signature_paths
  @signature_paths
end

#started_atObject (readonly)

Returns the value of attribute started_at.



13
14
15
# File 'lib/steep/server/type_check_controller.rb', line 13

def started_at
  @started_at
end

#work_done_progressObject (readonly)

Returns the value of attribute work_done_progress.



12
13
14
# File 'lib/steep/server/type_check_controller.rb', line 12

def work_done_progress
  @work_done_progress
end

Instance Method Details

#as_json(assignment:) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/steep/server/type_check_controller.rb', line 40

def as_json(assignment:)
  {
    guid: guid,
    library_uris: assigned_uris(assignment, library_paths),
    signature_uris: assigned_uris(assignment, signature_paths),
    code_uris: assigned_uris(assignment, code_paths),
    inline_uris: assigned_uris(assignment, inline_paths),
    priority_uris: priority_paths.map {|path| uri(path).to_s }
  }
end

#assigned_uris(assignment, paths) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/steep/server/type_check_controller.rb', line 51

def assigned_uris(assignment, paths)
  paths.filter_map do |target_path|
    if assignment =~ target_path
      [target_path[0].to_s, uri(target_path[1]).to_s]
    end
  end
end

#checked(path, target) ⇒ Object



98
99
100
101
102
103
# File 'lib/steep/server/type_check_controller.rb', line 98

def checked(path, target)
  target_path = [target.name, path] #: target_and_path

  raise unless checking_path?(target_path)
  checked_paths << target_path
end

#checking_path?(target_path) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/steep/server/type_check_controller.rb', line 92

def checking_path?(target_path)
  [library_paths, signature_paths, code_paths, inline_paths].any? do |paths|
    paths.include?(target_path)
  end
end

#each_path(&block) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/steep/server/type_check_controller.rb', line 71

def each_path(&block)
  if block
    each_target_path do |_target, path|
      yield path
    end
  else
    enum_for :each_path
  end
end

#each_target_path(&block) ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/steep/server/type_check_controller.rb', line 81

def each_target_path(&block)
  if block
    library_paths.each(&block)
    signature_paths.each(&block)
    code_paths.each(&block)
    inline_paths.each(&block)
  else
    enum_for :each_target_path
  end
end

#each_unchecked_code_target_path(&block) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/steep/server/type_check_controller.rb', line 131

def each_unchecked_code_target_path(&block)
  if block
    code_paths.each do |target_path|
      unless checked_paths.include?(target_path)
        yield target_path
      end
    end
  else
    enum_for :each_unchecked_code_target_path
  end
end

#each_unchecked_inline_target_path(&block) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/steep/server/type_check_controller.rb', line 167

def each_unchecked_inline_target_path(&block)
  if block
    inline_paths.each do |target_path|
      unless checked_paths.include?(target_path)
        yield target_path
      end
    end
  else
    enum_for :each_unchecked_inline_target_path
  end
end

#each_unchecked_library_target_path(&block) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/steep/server/type_check_controller.rb', line 143

def each_unchecked_library_target_path(&block)
  if block
    library_paths.each do |target_path|
      unless checked_paths.include?(target_path)
        yield target_path
      end
    end
  else
    enum_for :each_unchecked_library_target_path
  end
end

#each_unchecked_path(&block) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/steep/server/type_check_controller.rb', line 109

def each_unchecked_path(&block)
  if block
    each_unchecked_target_path do |_target, path|
      yield path
    end
  else
    enum_for :each_unchecked_path
  end
end

#each_unchecked_signature_target_path(&block) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
# File 'lib/steep/server/type_check_controller.rb', line 155

def each_unchecked_signature_target_path(&block)
  if block
    signature_paths.each do |target_path|
      unless checked_paths.include?(target_path)
        yield target_path
      end
    end
  else
    enum_for :each_unchecked_signature_target_path
  end
end

#each_unchecked_target_path(&block) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/steep/server/type_check_controller.rb', line 119

def each_unchecked_target_path(&block)
  if block
    each_target_path do |target_path|
      unless checked_paths.include?(target_path)
        yield target_path
      end
    end
  else
    enum_for :each_unchecked_target_path
  end
end

#empty?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/steep/server/type_check_controller.rb', line 63

def empty?
  total == 0
end

#finished?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/steep/server/type_check_controller.rb', line 105

def finished?
  total <= checked_paths.size
end

#merge!(request) ⇒ Object



179
180
181
182
183
184
185
186
# File 'lib/steep/server/type_check_controller.rb', line 179

def merge!(request)
  library_paths.merge(request.each_unchecked_library_target_path)
  signature_paths.merge(request.each_unchecked_signature_target_path)
  code_paths.merge(request.each_unchecked_code_target_path)
  inline_paths.merge(request.each_unchecked_inline_target_path)

  self
end

#percentageObject



67
68
69
# File 'lib/steep/server/type_check_controller.rb', line 67

def percentage
  checked_paths.size * 100 / total
end

#report_progress!(value = true) ⇒ Object



31
32
33
34
# File 'lib/steep/server/type_check_controller.rb', line 31

def report_progress!(value = true)
  @report_progress = value
  self
end

#totalObject



59
60
61
# File 'lib/steep/server/type_check_controller.rb', line 59

def total
  library_paths.size + signature_paths.size + code_paths.size + inline_paths.size
end

#uri(path) ⇒ Object



36
37
38
# File 'lib/steep/server/type_check_controller.rb', line 36

def uri(path)
  Steep::PathHelper.to_uri(path)
end