wcc-api 0.1.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49899b2b757d3a8867d8cab417abe229485607ce
4
- data.tar.gz: 6dc8fd8bc6b4e698ff55b815be2433ed47f93f63
3
+ metadata.gz: 8b9ffb1ca9873f835817d010c263b3119ebd9d7f
4
+ data.tar.gz: b9c2eb273451c15f9448852e4aba17ae6482cd65
5
5
  SHA512:
6
- metadata.gz: 38b967edc48dbc84cbf5de4e192308ed92fc0a57c607735ee9e773b3e63d66b13401be53fbebbc5d0f13f6aeaff8dfe7d64e89b46e96d2242d88c1ce4cb67178
7
- data.tar.gz: 9b2a844b784e8cc7cb6c80d72cc6917b486933514a2fad24898c6103f2d2c2cddfb3f41ad739c0906b79b236e1bc6f0b50a9d4133c2504fbaed596a79594d67a
6
+ metadata.gz: 3363843ade51012c9619dc76949268190b76bce8d8cb4b684034e1bb222c39f589e91f2d27786354c6794baeda43a3cc480ab6d9e02dd0366412c984397af503
7
+ data.tar.gz: 3d48bb1a95ba2b631d3f976f07f74dfaf47909417570e1be8ce489b06bd83279043fef88204b1f18b163ecbf38483462ae08eb196f31ae4ceaf18f6fa8e3a8dd
@@ -0,0 +1,41 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.3.3-node
6
+ steps:
7
+ - checkout
8
+ # Restore bundle cache
9
+ - restore_cache:
10
+ key: gem-{{ checksum "wcc-api.gemspec" }}
11
+
12
+ # copy env
13
+ - run: cp .env.example .env
14
+
15
+ # Bundle install dependencies
16
+ - run: bundle install --path /tmp/vendor/bundle
17
+
18
+ # Store bundle cache
19
+ - save_cache:
20
+ key: gem-{{ checksum "wcc-api.gemspec" }}
21
+ paths:
22
+ - /tmp/vendor/bundle
23
+
24
+ # run rubocop
25
+ - type: shell
26
+ command: |
27
+ bundle exec rubocop
28
+
29
+ # Run rspec in parallel
30
+ - type: shell
31
+ command: |
32
+ bundle exec rspec --profile 10 \
33
+ --format RspecJunitFormatter \
34
+ --out test_results/rspec.xml \
35
+ --format documentation \
36
+ --order rand \
37
+ $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
38
+
39
+ # Save test results for timing analysis
40
+ - store_test_results:
41
+ path: test_results
File without changes
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,190 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ DisplayCopNames: true
5
+ TargetRubyVersion: 2.3
6
+ Exclude:
7
+ # generated by rails/binstubs
8
+ - 'bin/**/*'
9
+
10
+ # generated by guard
11
+ - 'Guardfile'
12
+
13
+ # 3rd party
14
+ - 'vendor/**/*'
15
+ - 'lib/**/*'
16
+
17
+ Style/Documentation:
18
+ Enabled: false
19
+
20
+ Style/BlockDelimiters:
21
+ Exclude:
22
+ # we like the `let(:foo) {}` syntax in specs
23
+ - 'spec/**/*.rb'
24
+
25
+ Style/ClassAndModuleChildren:
26
+ EnforcedStyle: compact
27
+
28
+ Style/FormatStringToken:
29
+ EnforcedStyle: template
30
+
31
+ Style/RegexpLiteral:
32
+ Enabled: false
33
+
34
+ Metrics/BlockLength:
35
+ Exclude:
36
+ # spec files that might have a big describe
37
+ - 'spec/**/*.rb'
38
+
39
+ Style/BracesAroundHashParameters:
40
+ Enabled: false
41
+
42
+ Lint/AssignmentInCondition:
43
+ Enabled: false
44
+
45
+ Style/EmptyMethod:
46
+ EnforcedStyle: expanded
47
+
48
+ Style/Alias:
49
+ EnforcedStyle: prefer_alias_method
50
+
51
+ Style/NumericPredicate:
52
+ EnforcedStyle: comparison
53
+
54
+ Layout/AlignParameters:
55
+ EnforcedStyle: with_fixed_indentation
56
+
57
+ Layout/IndentFirstHashElement:
58
+ EnforcedStyle: consistent
59
+
60
+ Layout/AlignHash:
61
+ # allow coder to get around alignment rules by explicitly defining the hash param
62
+ EnforcedLastArgumentHashStyle: ignore_explicit
63
+
64
+ Layout/MultilineMethodCallIndentation:
65
+ EnforcedStyle: indented
66
+
67
+ Layout/MultilineOperationIndentation:
68
+ EnforcedStyle: indented
69
+
70
+ Rails:
71
+ Enabled: true
72
+
73
+ # These are all the cops that are disabled in the default configuration.
74
+
75
+ Layout/FirstArrayElementLineBreak:
76
+ Description: >-
77
+ Checks for a line break before the first element in a
78
+ multi-line array.
79
+ Enabled: true
80
+
81
+ Layout/FirstHashElementLineBreak:
82
+ Description: >-
83
+ Checks for a line break before the first element in a
84
+ multi-line hash.
85
+ Enabled: true
86
+
87
+ Layout/FirstMethodArgumentLineBreak:
88
+ Description: >-
89
+ Checks for a line break before the first argument in a
90
+ multi-line method call.
91
+ Enabled: false
92
+
93
+ Layout/FirstMethodParameterLineBreak:
94
+ Description: >-
95
+ Checks for a line break before the first parameter in a
96
+ multi-line method parameter definition.
97
+ Enabled: true
98
+
99
+ Layout/MultilineAssignmentLayout:
100
+ Description: 'Check for a newline after the assignment operator in multi-line assignments.'
101
+ StyleGuide: '#indent-conditional-assignment'
102
+ Enabled: true
103
+
104
+ Rails/SaveBang:
105
+ Description: 'Identifies possible cases where Active Record save! or related should be used.'
106
+ StyleGuide: 'https://github.com/bbatsov/rails-style-guide#save-bang'
107
+ Enabled: false
108
+
109
+ Style/AutoResourceCleanup:
110
+ Description: 'Suggests the usage of an auto resource cleanup version of a method (if available).'
111
+ Enabled: true
112
+
113
+ Style/CollectionMethods:
114
+ Description: 'Preferred collection methods.'
115
+ StyleGuide: '#map-find-select-reduce-size'
116
+ Enabled: true
117
+
118
+ Style/Copyright:
119
+ Description: 'Include a copyright notice in each file before any code.'
120
+ Enabled: false
121
+
122
+ Style/DocumentationMethod:
123
+ Description: 'Public methods.'
124
+ Enabled: false
125
+ Exclude:
126
+ - 'spec/**/*'
127
+ - 'test/**/*'
128
+
129
+ Style/ImplicitRuntimeError:
130
+ Description: >-
131
+ Use `raise` or `fail` with an explicit exception class and
132
+ message, rather than just a message.
133
+ Enabled: true
134
+
135
+ Style/InlineComment:
136
+ Description: 'Avoid trailing inline comments.'
137
+ Enabled: true
138
+
139
+ Style/MethodCallWithArgsParentheses:
140
+ Description: 'Use parentheses for method calls with arguments.'
141
+ StyleGuide: '#method-invocation-parens'
142
+ Enabled: false
143
+
144
+ Style/MethodCalledOnDoEndBlock:
145
+ Description: 'Avoid chaining a method call on a do...end block.'
146
+ StyleGuide: '#single-line-blocks'
147
+ # TODO: enable after fixing todos
148
+ Enabled: false
149
+ Exclude:
150
+ - 'spec/**/*'
151
+
152
+ Style/MissingElse:
153
+ Description: >-
154
+ Require if/case expressions to have an else branches.
155
+ If enabled, it is recommended that
156
+ Style/UnlessElse and Style/EmptyElse be enabled.
157
+ This will conflict with Style/EmptyElse if
158
+ Style/EmptyElse is configured to style "both"
159
+ Enabled: false
160
+ EnforcedStyle: both
161
+ SupportedStyles:
162
+ # if - warn when an if expression is missing an else branch
163
+ # case - warn when a case expression is missing an else branch
164
+ # both - warn when an if or case expression is missing an else branch
165
+ - if
166
+ - case
167
+ - both
168
+
169
+ Style/OptionHash:
170
+ Description: "Don't use option hashes when you can use keyword arguments."
171
+ Enabled: true
172
+
173
+ Style/ReturnNil:
174
+ Description: 'Use return instead of return nil.'
175
+ Enabled: true
176
+
177
+ Style/Send:
178
+ Description: 'Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` may overlap with existing methods.'
179
+ StyleGuide: '#prefer-public-send'
180
+ Enabled: true
181
+ Exclude:
182
+ - 'spec/**/*'
183
+
184
+ Style/StringMethods:
185
+ Description: 'Checks if configured preferred methods are used over non-preferred.'
186
+ Enabled: false
187
+
188
+ Style/SingleLineBlockParams:
189
+ Description: 'Enforces the names of some block params.'
190
+ Enabled: false
@@ -0,0 +1,63 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-02-11 12:22:05 -0600 using RuboCop version 0.64.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Metrics/AbcSize:
11
+ Max: 56
12
+
13
+ # Offense count: 1
14
+ # Configuration parameters: CountComments, ExcludedMethods.
15
+ # ExcludedMethods: refine
16
+ Metrics/BlockLength:
17
+ Max: 31
18
+
19
+ # Offense count: 4
20
+ # Configuration parameters: CountComments, ExcludedMethods.
21
+ Metrics/MethodLength:
22
+ Max: 25
23
+
24
+ # Offense count: 2
25
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
26
+ # NamePrefix: is_, has_, have_
27
+ # NamePrefixBlacklist: is_, has_, have_
28
+ # NameWhitelist: is_a?
29
+ # MethodDefinitionMacros: define_method, define_singleton_method
30
+ Naming/PredicateName:
31
+ Exclude:
32
+ - 'spec/**/*'
33
+ - 'lib/wcc/api/json/pagination.rb'
34
+
35
+ # Offense count: 5
36
+ # Cop supports --auto-correct.
37
+ # Configuration parameters: AutoCorrect, EnforcedStyle.
38
+ # SupportedStyles: nested, compact
39
+ Style/ClassAndModuleChildren:
40
+ Exclude:
41
+ - 'lib/wcc/api/railtie.rb'
42
+ - 'lib/wcc/api/rest_client/http_adapter.rb'
43
+ - 'lib/wcc/api/rest_client/typhoeus_adapter.rb'
44
+ - 'lib/wcc/api/version.rb'
45
+
46
+ # Offense count: 2
47
+ # Cop supports --auto-correct.
48
+ Style/IfUnlessModifier:
49
+ Exclude:
50
+ - 'lib/wcc/api/json/pagination.rb'
51
+
52
+ # Offense count: 1
53
+ # Configuration parameters: SuspiciousParamNames.
54
+ # SuspiciousParamNames: options, opts, args, params, parameters
55
+ Style/OptionHash:
56
+ Exclude:
57
+ - 'lib/wcc/api/controller_helpers.rb'
58
+
59
+ # Offense count: 11
60
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
61
+ # URISchemes: http, https
62
+ Metrics/LineLength:
63
+ Max: 142
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 wcc-api.gemspec
@@ -0,0 +1,32 @@
1
+ directories %w[lib spec]
2
+
3
+ group :red_green_refactor, halt_on_fail: true do
4
+ guard :rspec, cmd: 'bundle exec rspec --order rand', all_on_start: false do
5
+ require 'guard/rspec/dsl'
6
+ dsl = Guard::RSpec::Dsl.new(self)
7
+
8
+ # RSpec files
9
+ rspec = dsl.rspec
10
+ watch(rspec.spec_helper) { rspec.spec_dir }
11
+ watch(rspec.spec_support) { rspec.spec_dir }
12
+ watch(rspec.spec_files)
13
+
14
+ # Ruby files
15
+ ruby = dsl.ruby
16
+ dsl.watch_spec_files_for(ruby.lib_files)
17
+ end
18
+
19
+ guard :rubocop, cli: ['--display-cop-names'] do
20
+ watch(%r{.+\.rb$})
21
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
22
+ end
23
+ end
24
+
25
+ group :autofix do
26
+ guard :rubocop, all_on_start: false, cli: ['--auto-correct', '--display-cop-names'] do
27
+ watch(%r{.+\.rb$})
28
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
29
+ end
30
+ end
31
+
32
+ scope group: :red_green_refactor
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'bundler/gem_tasks'
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require 'rubygems'
16
+ require 'bundler/setup'
17
+
18
+ load Gem.bin_path('rspec-core', 'rspec')
@@ -1,17 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'wcc'
2
4
  require 'wcc/api/version'
3
5
 
4
- module WCC
5
- module API
6
- PROJECT_ROOT = File.expand_path(File.join(__FILE__, '..', '..', '..'))
7
- end
6
+ module WCC::API
7
+ PROJECT_ROOT = File.expand_path(File.join(__FILE__, '..', '..', '..'))
8
8
  end
9
9
 
10
- if defined?(Rails)
11
- require 'wcc/api/railtie'
12
- end
10
+ require 'wcc/api/railtie' if defined?(Rails)
13
11
 
14
12
  require 'wcc/api/base_query'
15
13
  require 'wcc/api/json'
14
+ require 'wcc/api/controller_helpers'
15
+ require 'wcc/api/rest_client'
16
16
  require 'wcc/api/view_helpers'
17
-
@@ -0,0 +1,69 @@
1
+ module WCC::API::ActiveRecordShim
2
+ def self.included(base)
3
+ base.public_send :include, InstanceMethods
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module InstanceMethods
8
+ def attributes
9
+ raw.keys.each_with_object({}) do |key, h|
10
+ next unless respond_to?(key)
11
+
12
+ val = public_send(key)
13
+ h[key] =
14
+ if val.is_a? Array
15
+ val.map { |v| v.respond_to?(:to_h) ? v.to_h : v }
16
+ else
17
+ val.respond_to?(:to_h) ? val.to_h : val
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ module ClassMethods
24
+ def find(id)
25
+ client.public_send(endpoint).find(id)
26
+ end
27
+
28
+ def find_all(**filters)
29
+ client.public_send(endpoint).list(filters)
30
+ end
31
+
32
+ def find_by(**filters)
33
+ raise ArgumentError, "You must provide at least one filter" if filters.empty?
34
+
35
+ find_all(filters).first
36
+ end
37
+
38
+ def model_name
39
+ name
40
+ end
41
+
42
+ def table_name
43
+ endpoint
44
+ end
45
+
46
+ def unscoped
47
+ yield
48
+ end
49
+
50
+ def find_in_batches(options, &block)
51
+ options = options ? options.dup : {}
52
+ batch_size = options.delete(:batch_size) || 1000
53
+ skip_param = [:skip, :offset]
54
+
55
+ filter = {
56
+ limit: batch_size,
57
+ offset: options.delete(:start) || 0
58
+ }
59
+
60
+ find_all(filter).each_slice(batch_size, &block)
61
+ end
62
+
63
+ def where(**conditions)
64
+ # TODO: return a Query object that implements more of the ActiveRecord query interface
65
+ # https://guides.rubyonrails.org/active_record_querying.html#conditions
66
+ find_all(conditions)
67
+ end
68
+ end
69
+ end