wcc-contentful 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +51 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +240 -0
  6. data/.rubocop_todo.yml +13 -0
  7. data/CHANGELOG.md +7 -1
  8. data/Gemfile +4 -2
  9. data/Guardfile +36 -0
  10. data/README.md +1 -1
  11. data/Rakefile +5 -3
  12. data/bin/rspec +3 -0
  13. data/lib/generators/wcc/USAGE +24 -0
  14. data/lib/generators/wcc/menu_generator.rb +67 -0
  15. data/lib/generators/wcc/templates/.keep +0 -0
  16. data/lib/generators/wcc/templates/Procfile +3 -0
  17. data/lib/generators/wcc/templates/contentful_shell_wrapper +342 -0
  18. data/lib/generators/wcc/templates/menu/generated_add_menus.ts +85 -0
  19. data/lib/generators/wcc/templates/menu/menu.rb +25 -0
  20. data/lib/generators/wcc/templates/menu/menu_button.rb +25 -0
  21. data/lib/generators/wcc/templates/release +9 -0
  22. data/lib/generators/wcc/templates/wcc_contentful.rb +18 -0
  23. data/lib/wcc/contentful.rb +93 -26
  24. data/lib/wcc/contentful/client_ext.rb +15 -0
  25. data/lib/wcc/contentful/configuration.rb +93 -0
  26. data/lib/wcc/contentful/content_type_indexer.rb +153 -0
  27. data/lib/wcc/contentful/exceptions.rb +34 -0
  28. data/lib/wcc/contentful/graphql.rb +15 -0
  29. data/lib/wcc/contentful/graphql/builder.rb +172 -0
  30. data/lib/wcc/contentful/graphql/types.rb +54 -0
  31. data/lib/wcc/contentful/helpers.rb +28 -0
  32. data/lib/wcc/contentful/indexed_representation.rb +111 -0
  33. data/lib/wcc/contentful/model.rb +24 -0
  34. data/lib/wcc/contentful/model/menu.rb +7 -0
  35. data/lib/wcc/contentful/model/menu_button.rb +15 -0
  36. data/lib/wcc/contentful/model_builder.rb +151 -0
  37. data/lib/wcc/contentful/model_validators.rb +64 -0
  38. data/lib/wcc/contentful/model_validators/dsl.rb +165 -0
  39. data/lib/wcc/contentful/simple_client.rb +127 -0
  40. data/lib/wcc/contentful/simple_client/response.rb +160 -0
  41. data/lib/wcc/contentful/store.rb +8 -0
  42. data/lib/wcc/contentful/store/cdn_adapter.rb +79 -0
  43. data/lib/wcc/contentful/store/memory_store.rb +75 -0
  44. data/lib/wcc/contentful/store/postgres_store.rb +132 -0
  45. data/lib/wcc/contentful/version.rb +3 -1
  46. data/wcc-contentful.gemspec +49 -24
  47. metadata +261 -16
  48. data/lib/wcc/contentful/redirect.rb +0 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de8808034cae7552bdfa557eee3108f6912111d7
4
- data.tar.gz: 50c47e3584ddd52463337df3ab706cc6d0a811ce
3
+ metadata.gz: 5a48cb096dc5f511308f9ac747349bde4b79fe43
4
+ data.tar.gz: 981ea6e61c9af9f2da0f9a590ec70f9563d0303b
5
5
  SHA512:
6
- metadata.gz: cbb571fcbbabf959eee07bc9a3cf65138b96b686fb17bc8a41027beb1557501fa2d30c431272a6683cf9f1c76e4a60604038adc0a932b975dfc11327449d57c7
7
- data.tar.gz: 1e7c91101e32de497e23b5d2584fc15db949f0c4e3b1e80e08a17a77c01b8326d34fb3ce94a0d6f5b06df688d1a12ffb7a6b1e939c62e6270d027a7e1ca9afbb
6
+ metadata.gz: 05fdef20e3e9efce2dcda906059b815fa360a34caa7733d4b1cd6170ef31ab4ca3f0989517c05c5a0970aea0ec4aa08b8f1dfe625d452bbf354a468145a9fde3
7
+ data.tar.gz: 52e05e8c6f6011f9c3387e5e721b3459d31b92547b49f8c944eba2aef4a78ab87542fd36e7b5dd8fad18b4420dbe2190a3e3d15cfef337e5c5b75d80f59d27c6
@@ -0,0 +1,51 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.3.3-node
6
+ environment:
7
+ RAILS_ENV: test
8
+ POSTGRES_CONNECTION: postgresql://ubuntu:@127.0.0.1:5432/circle_ruby_test
9
+ - image: postgres:9.5
10
+ environment:
11
+ - POSTGRES_USER: ubuntu
12
+ - POSTGRES_DB: circle_ruby_test
13
+ steps:
14
+ - checkout
15
+ # Restore bundle cache
16
+ - restore_cache:
17
+ key: rails-{{ checksum "wcc-contentful.gemspec" }}
18
+
19
+ # Bundle install dependencies
20
+ - run: bundle install --path /tmp/vendor/bundle
21
+
22
+ # Store bundle cache
23
+ - save_cache:
24
+ key: rails-{{ checksum "wcc-contentful.gemspec" }}
25
+ paths:
26
+ - /tmp/vendor/bundle
27
+
28
+ # run Danger
29
+ # - type: shell
30
+ # command: |
31
+ # bundle exec danger
32
+
33
+ # run rubocop
34
+ - type: shell
35
+ command: |
36
+ bundle exec rubocop
37
+
38
+ # Run rspec in parallel
39
+ - type: shell
40
+ command: |
41
+ bundle exec rspec --profile 10 \
42
+ --format RspecJunitFormatter \
43
+ --out test_results/rspec.xml \
44
+ --format documentation \
45
+ --order rand \
46
+ $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
47
+
48
+ # Save test results for timing analysis
49
+ - store_test_results:
50
+ path: test_results
51
+
data/.gitignore CHANGED
@@ -11,3 +11,11 @@
11
11
  .rspec_status
12
12
 
13
13
  Gemfile.lock
14
+
15
+ # exports and error logs from contentful
16
+ contentful-export*
17
+ contentful-*-error-log-*
18
+
19
+ # User local env
20
+ .envrc
21
+ .env*
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --format documentation
2
2
  --color
3
3
  --require spec_helper
4
+ --order rand
@@ -0,0 +1,240 @@
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
+ # auto generated by rails
11
+
12
+ # Config files
13
+ - 'Guardfile'
14
+ - 'Dangerfile'
15
+
16
+ # 3rd party
17
+ - 'vendor/**/*'
18
+
19
+ # generator templates
20
+ - '**/templates/**/*'
21
+ - 'tmp/**/*'
22
+
23
+ Style/Documentation:
24
+ Enabled: false
25
+
26
+ Style/BlockDelimiters:
27
+ Exclude:
28
+ # we like the `let(:foo) {}` syntax in specs
29
+ - 'spec/**/*.rb'
30
+
31
+ Style/ClassAndModuleChildren:
32
+ EnforcedStyle: compact
33
+ Exclude:
34
+ - 'lib/wcc/contentful/version.rb'
35
+ # Generators need to define the "Wcc" module so it doesnt get underscored.
36
+ - 'lib/generators/**/*.rb'
37
+
38
+ Style/FormatStringToken:
39
+ EnforcedStyle: template
40
+
41
+ Metrics/BlockLength:
42
+ Exclude:
43
+ # config files where we expect long blocks
44
+ - 'danger-wcc.gemspec'
45
+ # spec files that might have a big describe
46
+ - 'spec/**/*.rb'
47
+ # dsl files https://stackoverflow.com/a/41187163
48
+
49
+ Metrics/CyclomaticComplexity:
50
+ Enabled: false
51
+
52
+ Metrics/AbcSize:
53
+ Enabled: false
54
+
55
+ Metrics/PerceivedComplexity:
56
+ Enabled: false
57
+
58
+ Metrics/BlockLength:
59
+ Enabled: false
60
+
61
+ Metrics/MethodLength:
62
+ Enabled: false
63
+
64
+ Metrics/ClassLength:
65
+ Enabled: false
66
+
67
+ Metrics/ModuleLength:
68
+ Exclude:
69
+ - 'spec/**/*.rb'
70
+
71
+ Performance/UnfreezeString:
72
+ Exclude:
73
+ - 'spec/**/*.rb'
74
+
75
+ Style/BracesAroundHashParameters:
76
+ Enabled: false
77
+
78
+ Lint/AssignmentInCondition:
79
+ Enabled: false
80
+
81
+ Lint/AmbiguousBlockAssociation:
82
+ Exclude:
83
+ - 'spec/generators/**/*.rb'
84
+
85
+ Style/EmptyMethod:
86
+ EnforcedStyle: expanded
87
+
88
+ Style/Alias:
89
+ EnforcedStyle: prefer_alias_method
90
+
91
+ Style/NumericPredicate:
92
+ EnforcedStyle: comparison
93
+
94
+ Style/RegexpLiteral:
95
+ Enabled: false
96
+
97
+ Style/ModuleFunction:
98
+ EnforcedStyle: extend_self
99
+
100
+ # Danger uses the 'fail' keyword for reporting errors
101
+ Style/SignalException:
102
+ Enabled: false
103
+
104
+ Layout/AlignParameters:
105
+ EnforcedStyle: with_fixed_indentation
106
+
107
+ Layout/IndentHash:
108
+ EnforcedStyle: consistent
109
+
110
+ Layout/AlignHash:
111
+ # allow coder to get around alignment rules by explicitly defining the hash param
112
+ EnforcedLastArgumentHashStyle: ignore_explicit
113
+
114
+ Layout/MultilineMethodCallIndentation:
115
+ EnforcedStyle: indented
116
+
117
+ Layout/MultilineOperationIndentation:
118
+ EnforcedStyle: indented
119
+
120
+
121
+ # These are all the cops that are disabled in the default configuration.
122
+
123
+ Layout/FirstArrayElementLineBreak:
124
+ Description: >-
125
+ Checks for a line break before the first element in a
126
+ multi-line array.
127
+ Enabled: true
128
+
129
+ Layout/FirstHashElementLineBreak:
130
+ Description: >-
131
+ Checks for a line break before the first element in a
132
+ multi-line hash.
133
+ Enabled: true
134
+
135
+ Layout/FirstMethodArgumentLineBreak:
136
+ Description: >-
137
+ Checks for a line break before the first argument in a
138
+ multi-line method call.
139
+ Enabled: false
140
+
141
+ Layout/FirstMethodParameterLineBreak:
142
+ Description: >-
143
+ Checks for a line break before the first parameter in a
144
+ multi-line method parameter definition.
145
+ Enabled: true
146
+
147
+ Layout/MultilineAssignmentLayout:
148
+ Description: 'Check for a newline after the assignment operator in multi-line assignments.'
149
+ StyleGuide: '#indent-conditional-assignment'
150
+ Enabled: true
151
+
152
+ Lint/MissingCopEnableDirective:
153
+ Exclude:
154
+ - 'spec/fixtures/**/*'
155
+
156
+ Style/AutoResourceCleanup:
157
+ Description: 'Suggests the usage of an auto resource cleanup version of a method (if available).'
158
+ Enabled: true
159
+
160
+ Style/CollectionMethods:
161
+ Description: 'Preferred collection methods.'
162
+ StyleGuide: '#map-find-select-reduce-size'
163
+ Enabled: true
164
+
165
+ Style/Copyright:
166
+ Description: 'Include a copyright notice in each file before any code.'
167
+ Enabled: false
168
+
169
+ Style/DocumentationMethod:
170
+ Description: 'Public methods.'
171
+ Enabled: false
172
+ Exclude:
173
+ - 'spec/**/*'
174
+ - 'test/**/*'
175
+
176
+ Style/ImplicitRuntimeError:
177
+ Description: >-
178
+ Use `raise` or `fail` with an explicit exception class and
179
+ message, rather than just a message.
180
+ Enabled: true
181
+
182
+ Style/InlineComment:
183
+ Description: 'Avoid trailing inline comments.'
184
+ Enabled: true
185
+
186
+
187
+ Style/Lambda:
188
+ EnforcedStyle: literal
189
+
190
+ Style/MethodCallWithArgsParentheses:
191
+ Description: 'Use parentheses for method calls with arguments.'
192
+ StyleGuide: '#method-invocation-parens'
193
+ Enabled: false
194
+
195
+ Style/MethodCalledOnDoEndBlock:
196
+ Description: 'Avoid chaining a method call on a do...end block.'
197
+ StyleGuide: '#single-line-blocks'
198
+ Enabled: true
199
+ Exclude:
200
+ - 'spec/**/*'
201
+
202
+ Style/MissingElse:
203
+ Description: >-
204
+ Require if/case expressions to have an else branches.
205
+ If enabled, it is recommended that
206
+ Style/UnlessElse and Style/EmptyElse be enabled.
207
+ This will conflict with Style/EmptyElse if
208
+ Style/EmptyElse is configured to style "both"
209
+ Enabled: false
210
+ EnforcedStyle: both
211
+ SupportedStyles:
212
+ # if - warn when an if expression is missing an else branch
213
+ # case - warn when a case expression is missing an else branch
214
+ # both - warn when an if or case expression is missing an else branch
215
+ - if
216
+ - case
217
+ - both
218
+
219
+ Style/OptionHash:
220
+ Description: "Don't use option hashes when you can use keyword arguments."
221
+ Enabled: false
222
+
223
+ Style/ReturnNil:
224
+ Description: 'Use return instead of return nil.'
225
+ Enabled: true
226
+
227
+ Style/Send:
228
+ Description: 'Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` may overlap with existing methods.'
229
+ StyleGuide: '#prefer-public-send'
230
+ Enabled: true
231
+ Exclude:
232
+ - 'spec/**/*'
233
+
234
+ Style/StringMethods:
235
+ Description: 'Checks if configured preferred methods are used over non-preferred.'
236
+ Enabled: false
237
+
238
+ Style/SingleLineBlockParams:
239
+ Description: 'Enforces the names of some block params.'
240
+ Enabled: false
@@ -0,0 +1,13 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-02-23 09:06:45 -0600 using RuboCop version 0.52.1.
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: 49
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
11
+ # URISchemes: http, https
12
+ Metrics/LineLength:
13
+ Max: 105
@@ -10,4 +10,10 @@
10
10
 
11
11
  ## v0.0.3
12
12
 
13
- * Can now fetch Redirect models via slug, regardless of slug lettercase (uppercase or lowercase).
13
+ * Can now fetch Redirect models via slug, regardless of slug lettercase (uppercase or lowercase).
14
+
15
+ # v0.1.0
16
+
17
+ * Models are built dynamically from downloading the content_types via Contentful CDN
18
+ * 'Menu' and 'MenuItem' are defined and their structures are enforced via validation
19
+ * A GraphQL schema can optionally be generated to execute queries against Contentful
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
6
 
5
7
  # Specify your gem's dependencies in wcc-contentful.gemspec
6
8
  gemspec
@@ -0,0 +1,36 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ group :red_green_refactor, halt_on_fail: true do
7
+ guard :rspec, cmd: 'bundle exec rspec' do
8
+ require 'guard/rspec/dsl'
9
+ dsl = Guard::RSpec::Dsl.new(self)
10
+
11
+ # RSpec files
12
+ rspec = dsl.rspec
13
+ watch(rspec.spec_helper) { rspec.spec_dir }
14
+ watch(rspec.spec_support) { rspec.spec_dir }
15
+ watch(rspec.spec_files)
16
+
17
+ # Ruby files
18
+ ruby = dsl.ruby
19
+ watch(%r{lib/wcc/(.+)\.rb$}) { |m| rspec.spec.call("wcc/#{m[1]}") }
20
+ watch(%r{lib/generators/(.+)\.rb$}) { |m| rspec.spec.call("generators/#{m[1]}") }
21
+ end
22
+
23
+ guard :rubocop, cli: ['--display-cop-names'] do
24
+ watch(%r{.+\.rb$})
25
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
26
+ end
27
+ end
28
+
29
+ group :autofix do
30
+ guard :rubocop, all_on_start: false, cli: ['--auto-correct', '--display-cop-names'] do
31
+ watch(%r{.+\.rb$})
32
+ watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
33
+ end
34
+ end
35
+
36
+ scope group: :red_green_refactor
data/README.md CHANGED
@@ -50,4 +50,4 @@ The gem is available as open source under the terms of the [MIT License](http://
50
50
 
51
51
  ## Code of Conduct
52
52
 
53
- Everyone interacting in the WCC::Contentful projects codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/wcc-contentful/blob/master/CODE_OF_CONDUCT.md).
53
+ Everyone interacting in the WCC::Contentful project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/wcc-contentful/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ bundle exec rspec $*
@@ -0,0 +1,24 @@
1
+ Description:
2
+ Generates the necessary migrations and initializers to add WCC Menus
3
+ to your contentful space.
4
+
5
+ Example:
6
+ rails generate wcc:menu
7
+
8
+ This will install:
9
+ https://www.github.com/watermarkchurch/migration-cli
10
+
11
+ This will create:
12
+ db/migrate/[date]_generated_add_menus.ts -
13
+ this migration is run by the migration CLI to create menus in your
14
+ contentful space
15
+ bin/release -
16
+ Adds a release command to your rails app which runs migrations.
17
+ bin/contentful -
18
+ This bash script is a wrapper around various Contentful CLI tools, and
19
+ is invoked by bin/release to run migrations
20
+ Procfile -
21
+ Adds a release command to be invoked by Heroku which runs the script
22
+ in bin/release
23
+ config/initializers/wcc_contentful.rb -
24
+ This file will initialize the wcc_contentful gem with default options