okay 8.0.0 → 9.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 480936344226fb0983ee94c29f233d6a8b3c1c811e13f58430243b4d4cef27a7
4
- data.tar.gz: bd70ea5928905aa0123f45d3edb46ab41cc811c5bc8076a73a975d0ab8e967a1
3
+ metadata.gz: 771620de5d44a7098a96b5e95672a07582327108f8ebe18a0c7aadbfcaa6272e
4
+ data.tar.gz: 448f409cce2467dc0ecd9f3e940590c1620c69528fe011305848e3b63fe83c8f
5
5
  SHA512:
6
- metadata.gz: a8c3331f360a7f716ed90c8d215c260e425a21c5ee29fec75dccc78180028459c6046f5c698a7e9310fc473cfa12b290112aaacf2a30caa313261af6f2745c9f
7
- data.tar.gz: c3123c13c16a882d17d655ef928d415fb7531ed657884ce72af709d347a9ab20a5f3d4f3bcb1d6c00b53e363ac766c49a6f304a02d36109824e186674d3a4834
6
+ metadata.gz: '0678fc09142e31bf1fcee8199fad6121fad65d55f3d6d09cc89e46e6be10f35beaa539534e8ef5be709ae89576825686922d455818f1cd19f2a33f5acf949c38'
7
+ data.tar.gz: e2c75f5898ffbb543a63bc407df09ccadd7e98ea7dc7dfe29f25f72bf0159ac7df5b54c07a60223ffbd11d2fd5c32491d4fc3fd28abbd537b93e5641b55d736c
@@ -0,0 +1,2 @@
1
+ user=how-is
2
+ project=how_is
data/.rubocop.yml ADDED
@@ -0,0 +1,223 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ DisplayStyleGuide: true
4
+ TargetRubyVersion: 2.4
5
+ Exclude:
6
+ - 'okay.gemspec'
7
+ - 'bin/*'
8
+ - 'examples/*'
9
+ - '**/*~'
10
+ - 'spec/capture_warnings.rb'
11
+
12
+ # Exceptions should inherit from StandardError.
13
+ # (RuboCop default is to inherit from RuntimeError.)
14
+ Lint/InheritException:
15
+ EnforcedStyle: standard_error
16
+
17
+ Metrics/AbcSize:
18
+ Max: 17
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'spec/**/*_spec.rb'
23
+
24
+
25
+ # Getting this back to the default of 100 would be nice,
26
+ # but the few cases that exceed it don't seem overly concerning.
27
+ Metrics/ClassLength:
28
+ Max: 120
29
+
30
+ # Still try for 80, but we'll allow 110 because there's a not-insignificant
31
+ # number of cases where we have long lines.
32
+ #
33
+ # It may be worth revisiting this in the future and refactoring those lines.
34
+ Metrics/LineLength:
35
+ Max: 120
36
+ AllowHeredoc: true
37
+
38
+ # Too short methods lead to extraction of single-use methods, which can make
39
+ # the code easier to read (by naming things), but can also clutter the class
40
+ Metrics/MethodLength:
41
+ Max: 25
42
+
43
+ Metrics/ParameterLists:
44
+ Max: 6
45
+
46
+ Style/Alias:
47
+ EnforcedStyle: prefer_alias_method
48
+
49
+ # Most readable form.
50
+ Layout/AlignHash:
51
+ EnforcedHashRocketStyle: table
52
+ EnforcedColonStyle: table
53
+ # Disable because it wound up conflicting with a lot of things like:
54
+ # foo('bar',
55
+ # baz: 'asdf',
56
+ # beep: 'boop')
57
+ #
58
+ # I suspect these'll disappear when overarching architectural issues are
59
+ # addressed.
60
+ Enabled: false
61
+
62
+ Layout/AlignParameters:
63
+ # See Style/AlignedHash.
64
+ Enabled: false
65
+
66
+ # This codebase may be English, but some English words contain diacritics.
67
+ Style/AsciiComments:
68
+ Enabled: false
69
+
70
+ # Despite the fact that some English words contain diacritics, we want all
71
+ # method names to be writable by people who don't have an easy way to type
72
+ # words with diacritics.
73
+ Style/AsciiIdentifiers:
74
+ Enabled: true
75
+
76
+ # { ... } for multi-line blocks is okay, follow Weirichs rule instead:
77
+ # https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
78
+ Style/BlockDelimiters:
79
+ Enabled: false
80
+
81
+ # There's more nuance around this than RuboCop seems capable of.
82
+ Style/BracesAroundHashParameters:
83
+ Enabled: false
84
+
85
+ # Don't force use of Time or Date; DateTime is okay.
86
+ Style/DateTime:
87
+ Enabled: false
88
+
89
+ # Unicode is good, mkay?
90
+ Style/Encoding:
91
+ Enabled: true
92
+
93
+ Style/RedundantSelf:
94
+ Enabled: false
95
+
96
+ # Force Unix line endings.
97
+ Layout/EndOfLine:
98
+ Enabled: true
99
+ EnforcedStyle: lf
100
+
101
+ # A lot of the approaches I use for making things readable makes this angry.
102
+ # E.g., formatting multiple consecutive assignments so that the equal signs
103
+ # and values line up.
104
+ #
105
+ # foobar = 'blah'
106
+ # baz = 'asdf'
107
+ # beep = 'boop'
108
+ Layout/ExtraSpacing:
109
+ Enabled: false
110
+
111
+ # # bad
112
+ #
113
+ # format('%<greeting>s', greeting: 'Hello')
114
+ # format('%s', 'Hello')
115
+ #
116
+ # # good
117
+ #
118
+ # format('%{greeting}', greeting: 'Hello')
119
+ Style/FormatStringToken:
120
+ EnforcedStyle: template
121
+
122
+ # Freeze string literals to future-proof the code.
123
+ Style/FrozenStringLiteralComment:
124
+ Enabled: true
125
+ EnforcedStyle: always
126
+
127
+ # Mixing hash styles just looks silly.
128
+ # http://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/HashSyntax
129
+ Style/HashSyntax:
130
+ EnforcedStyle: no_mixed_keys
131
+
132
+ Layout/IndentHash:
133
+ Enabled: true
134
+ EnforcedStyle: consistent
135
+
136
+ Layout/IndentArray:
137
+ Enabled: true
138
+ EnforcedStyle: consistent
139
+
140
+ Style/ConditionalAssignment:
141
+ Enabled: false
142
+
143
+ # I deplore assignments in conditions and never want them in any codebase
144
+ # I have direct control over.
145
+ Style/ParenthesesAroundCondition:
146
+ AllowSafeAssignment: false
147
+ Lint/AssignmentInCondition:
148
+ AllowSafeAssignment: false
149
+
150
+ # Use [] for `%`-literal delimiters (e.g. for %q[]) that RuboCop doesn't define
151
+ # anything for. (E.g., %q[].)
152
+ #
153
+ # The reason I prefer [] instead of () is that most of the time I use
154
+ # `%`-literals is inside of function calls, and using () makes it blend in too
155
+ # much.
156
+ Style/PercentLiteralDelimiters:
157
+ Enabled: true
158
+ PreferredDelimiters:
159
+ default: "[]"
160
+ '%w': '[]'
161
+ '%W': '[]'
162
+
163
+ # `has_key?` and `has_value?` are clearer than `key?` and `value?`.
164
+ Style/PreferredHashMethods:
165
+ Enabled: true
166
+ EnforcedStyle: verbose
167
+
168
+ # do / end blocks should be used for side effects,
169
+ # methods that run a block for side effects and have
170
+ # a useful return value are rare, assign the return
171
+ # value to a local variable for those cases.
172
+ Style/MethodCalledOnDoEndBlock:
173
+ Enabled: true
174
+
175
+ # Indent method calls relative to the receiver, e.g.:
176
+ # foo \
177
+ # .bar \
178
+ # .baz \
179
+ # .asdf
180
+ Layout/MultilineMethodCallIndentation:
181
+ EnforcedStyle: indented_relative_to_receiver
182
+
183
+ # Indenting the chained dots beneath each other is not supported by this cop,
184
+ # see https://github.com/bbatsov/rubocop/issues/1633
185
+ Layout/MultilineOperationIndentation:
186
+ Enabled: false
187
+
188
+ # {'foo' => 'bar'} not { 'foo' => 'bar' }
189
+ Layout/SpaceInsideHashLiteralBraces:
190
+ Enabled: true
191
+ EnforcedStyle: no_space
192
+
193
+ # I find "foo > 0" more readable than "foo.positive?" personally.
194
+ Style/NumericPredicate:
195
+ Enabled: false
196
+
197
+ # https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/RegexpLiteral
198
+ Style/RegexpLiteral:
199
+ Enabled: false
200
+
201
+ # Use double quotes everywhere by default.
202
+ Style/StringLiterals:
203
+ EnforcedStyle: double_quotes
204
+
205
+ # Prefer [:foo, :bar] over %i[foo bar].
206
+ Style/SymbolArray:
207
+ Enabled: true
208
+ EnforcedStyle: brackets
209
+
210
+ # Prefer ["foo", "bar"] over %w[foo bar].
211
+ Style/WordArray:
212
+ Enabled: true
213
+ EnforcedStyle: brackets
214
+
215
+ # Require parentheses around complex ternary conditions.
216
+ Style/TernaryParentheses:
217
+ Enabled: true
218
+ EnforcedStyle: require_parentheses_when_complex
219
+
220
+ # Require a comma after the last item in an array or hash if each item is on
221
+ # its own line.
222
+ Style/TrailingCommaInLiteral:
223
+ EnforcedStyleForMultiline: comma
data/.travis.yml CHANGED
@@ -1,5 +1,25 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.15.0
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
7
+ - ruby-head
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm:
12
+ - ruby-head
13
+
14
+ before_install:
15
+ - gem install bundler
16
+
17
+ # See https://bors.tech/documentation/getting-started/
18
+ branches:
19
+ only:
20
+ # This is where pull requests from "bors r+" are built.
21
+ - staging
22
+ # This is where pull requests from "bors try" are built.
23
+ - trying
24
+ # Build pull requests.
25
+ - master
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in okay.gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
data/lib/okay.rb CHANGED
@@ -1,5 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "okay/version"
2
4
 
5
+ ##
6
+ # A collection of classes/modules providing simple implementations of
7
+ # useful things.
3
8
  module Okay
4
9
  # Your code goes here...
5
10
  end
data/lib/okay/default.rb CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "okay/version"
2
4
 
5
+ # :nodoc:
3
6
  module Okay
7
+ # :nodoc:
4
8
  module DefaultValue
5
9
  def self.nil?
6
10
  true
data/lib/okay/graphql.rb CHANGED
@@ -1,8 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "okay/version"
2
4
  require "okay/http"
3
5
  require "json"
4
6
 
5
7
  module Okay
8
+ ##
9
+ # A simple GraphQL client.
10
+ #
6
11
  # Example usage:
7
12
  #
8
13
  # require "okay/graphql"
@@ -21,6 +26,8 @@ module Okay
21
26
  end
22
27
  end
23
28
 
29
+ ##
30
+ # Implements the GraphQL DSL.
24
31
  class QueryDSL
25
32
  def initialize(indent = 0, &query)
26
33
  @query = ""
@@ -31,13 +38,13 @@ module Okay
31
38
 
32
39
  def method_missing(name, *args, **kwargs, &block)
33
40
  query_part = @indent_str + name.to_s
34
- if args.length > 0 || kwargs.length > 0
41
+ if !args.empty? || !kwargs.empty?
35
42
  query_part += "("
36
43
 
37
44
  query_args = []
38
45
  query_args += args unless args.empty?
39
- query_args += kwargs.map { |k,v|
40
- [k,v.inspect].join(": ")
46
+ query_args += kwargs.map { |k, v|
47
+ [k, v.inspect].join(": ")
41
48
  }
42
49
  query_part += query_args.join(", ")
43
50
 
@@ -58,6 +65,8 @@ module Okay
58
65
  end
59
66
  end
60
67
 
68
+ ##
69
+ # A class for submitting GraphQL queries.
61
70
  class Query
62
71
  def initialize(raw_query = nil, &query)
63
72
  @query = raw_query || QueryDSL.new(&query)
@@ -83,12 +92,13 @@ module Okay
83
92
  end
84
93
 
85
94
  data = {
86
- "query" => to_s
95
+ "query" => to_s,
87
96
  }.to_json
88
97
  Okay::HTTP.post(url, headers: headers, data: data)
89
98
  end
90
99
 
91
- private
100
+ private
101
+
92
102
  def default_github_headers(token)
93
103
  {
94
104
  "Accept" => "application/vnd.github.v4.idl",
@@ -103,6 +113,8 @@ module Okay
103
113
  end
104
114
  end
105
115
 
116
+ # :nodoc:
117
+ # rubocop:disable all
106
118
  class Object
107
119
  def self.const_missing(name)
108
120
  # HACK: if const_missing is called inside Okay::GraphQL#initialize,
@@ -122,3 +134,4 @@ class Object
122
134
  end
123
135
  end
124
136
  end
137
+ # rubocop:enable all
data/lib/okay/http.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "okay/version"
2
4
  require "openssl/better_defaults"
3
5
  require "net/https"
@@ -5,7 +7,9 @@ require "cacert"
5
7
 
6
8
  Cacert.set_in_env
7
9
 
10
+ # :nodoc:
8
11
  module Net
12
+ # :nodoc:
9
13
  class HTTPResponse
10
14
  # Returns false if the server encountered an error, true otherwise.
11
15
  def okay?
@@ -29,18 +33,18 @@ module Net
29
33
  #
30
34
  # Okay::HTTP.get("https://example.org/blah.json").or_raise!.from_json
31
35
  def from_json
36
+ return nil unless okay?
37
+
32
38
  require "json"
33
39
 
34
- if okay?
35
- JSON.parse(body)
36
- else
37
- nil
38
- end
40
+ JSON.parse(body)
39
41
  end
40
42
  end
41
43
  end
42
44
 
43
45
  module Okay
46
+ ##
47
+ # A wrapper around Net::HTTP, focused on ease of use and flexibility.
44
48
  module HTTP
45
49
  RedirectLimitError = Class.new(StandardError)
46
50
 
@@ -95,7 +99,7 @@ module Okay
95
99
 
96
100
  options = {
97
101
  # If the URI starts with "https://", enable SSL/TLS.
98
- use_ssl: (uri.scheme == "https")
102
+ use_ssl: (uri.scheme == "https"),
99
103
  }
100
104
 
101
105
  # Net::HTTP.start() keeps a connection to the host alive
@@ -106,7 +110,7 @@ module Okay
106
110
  request_class = Net::HTTP.const_get(http_method)
107
111
 
108
112
  # Create the request object, but don't send it.
109
- request = request_class.new(uri)
113
+ request = request_class.new(uri)
110
114
 
111
115
  headers.each do |k, v|
112
116
  request[k] = v
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "okay/version"
4
+ require "okay/warning_helpers"
5
+ require "pathname"
6
+
7
+ module Okay
8
+ ##
9
+ # An extremely simple templating engine.
10
+ #
11
+ # General usage:
12
+ #
13
+ # template = Okay::Template.new("./templates")
14
+ # puts template.apply("some_template.html", {"some_key": "some value"})
15
+ # template.directory #=> "./templates"
16
+ class Template
17
+ include WarningHelpers
18
+
19
+ attr_reader :directory
20
+
21
+ ##
22
+ # Create an Okay::Templates object.
23
+ #
24
+ # @param directory [String] Path of the directory containing the templates.
25
+ def initialize(directory)
26
+ @directory = directory
27
+ end
28
+
29
+ ##
30
+ # Apply the template referenced by +template_name+ to +data+.
31
+ #
32
+ # @param template_name [String] Name of the template to use,
33
+ # relative to +@directory+ (as passed to +#initialize+).
34
+ # @param data [Hash] Data to apply the template to.
35
+ #
36
+ # @return [String] Result of applying the template to +data+.
37
+ def apply(template_name, data)
38
+ template_file = Pathname.new(@directory).join(template_name)
39
+ template = template_file.read
40
+
41
+ # Silence warnings while applying the template, since we don't
42
+ # generally care about unused keys.
43
+ silence_warnings { Kernel.format(template, data) }
44
+ end
45
+ end
46
+ end
data/lib/okay/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Okay
2
- VERSION = "8.0.0"
4
+ VERSION = "9.0.0"
3
5
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "okay/version"
4
+
5
+ module Okay
6
+ ##
7
+ # Helper functions for suppressing warnings when we know it's okay.
8
+ module WarningHelpers
9
+ def silence_warnings(&block)
10
+ with_warnings(nil, &block)
11
+ end
12
+
13
+ def with_warnings(flag, &_block)
14
+ old_verbose = $VERBOSE
15
+ $VERBOSE = flag
16
+ yield
17
+ ensure
18
+ $VERBOSE = old_verbose
19
+ end
20
+ end
21
+ end
data/okay.gemspec CHANGED
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  # coding: utf-8
3
+
2
4
  lib = File.expand_path("../lib", __FILE__)
3
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
6
  require "okay/version"
@@ -24,8 +26,8 @@ Gem::Specification.new do |spec|
24
26
  spec.add_runtime_dependency "openssl-better_defaults"
25
27
  spec.add_runtime_dependency "cacert"
26
28
 
27
- spec.add_development_dependency "bundler", "~> 1.15"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
30
- spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", "~> 12.3"
31
+ spec.add_development_dependency "rspec", "~> 3.8"
32
+ spec.add_development_dependency "rubocop", "~> 0.49.1"
31
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okay
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.0
4
+ version: 9.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ellen Marie Dash
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-30 00:00:00.000000000 Z
11
+ date: 2019-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl-better_defaults
@@ -44,56 +44,56 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.15'
47
+ version: '2.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.15'
54
+ version: '2.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '12.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '12.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '3.8'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '3.8'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.49.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.49.1
97
97
  description: Okay, minimalist implementations of common utilities in Ruby. E.g., HTTP
98
98
  fetchers.
99
99
  email:
@@ -102,8 +102,10 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github_changelog_generator"
105
106
  - ".gitignore"
106
107
  - ".rspec"
108
+ - ".rubocop.yml"
107
109
  - ".travis.yml"
108
110
  - CODE_OF_CONDUCT.md
109
111
  - Gemfile
@@ -118,7 +120,9 @@ files:
118
120
  - lib/okay/default.rb
119
121
  - lib/okay/graphql.rb
120
122
  - lib/okay/http.rb
123
+ - lib/okay/template.rb
121
124
  - lib/okay/version.rb
125
+ - lib/okay/warning_helpers.rb
122
126
  - okay.gemspec
123
127
  homepage: https://github.com/duckinator/okay
124
128
  licenses:
@@ -139,8 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
143
  - !ruby/object:Gem::Version
140
144
  version: '0'
141
145
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.6
146
+ rubygems_version: 3.0.2
144
147
  signing_key:
145
148
  specification_version: 4
146
149
  summary: Okay, minimalist implementations of common utilities.