puzzly_api_plugin 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +43 -0
  3. data/.gitignore +16 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +11 -0
  6. data/Gemfile +8 -0
  7. data/LICENSE.txt +21 -0
  8. data/Linux Mint Ruby Setup.md +1 -0
  9. data/README.md +17 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/lib/puzzly_api_plugin/collection/apis.rb +20 -0
  14. data/lib/puzzly_api_plugin/collection/caches.rb +20 -0
  15. data/lib/puzzly_api_plugin/collection/collection.rb +24 -0
  16. data/lib/puzzly_api_plugin/collection/contexts.rb +12 -0
  17. data/lib/puzzly_api_plugin/collection/modules.rb +16 -0
  18. data/lib/puzzly_api_plugin/collection/queries.rb +20 -0
  19. data/lib/puzzly_api_plugin/collection/schemas.rb +16 -0
  20. data/lib/puzzly_api_plugin/collection/tables.rb +20 -0
  21. data/lib/puzzly_api_plugin/collection/topics.rb +24 -0
  22. data/lib/puzzly_api_plugin/fields.rb +82 -0
  23. data/lib/puzzly_api_plugin/generator.rb +62 -0
  24. data/lib/puzzly_api_plugin/identity.rb +15 -0
  25. data/lib/puzzly_api_plugin/jsonable.rb +15 -0
  26. data/lib/puzzly_api_plugin/metadata/api.rb +33 -0
  27. data/lib/puzzly_api_plugin/metadata/cache.rb +33 -0
  28. data/lib/puzzly_api_plugin/metadata/context.rb +21 -0
  29. data/lib/puzzly_api_plugin/metadata/metadata.rb +27 -0
  30. data/lib/puzzly_api_plugin/metadata/module.rb +27 -0
  31. data/lib/puzzly_api_plugin/metadata/query.rb +33 -0
  32. data/lib/puzzly_api_plugin/metadata/schema.rb +33 -0
  33. data/lib/puzzly_api_plugin/metadata/table.rb +33 -0
  34. data/lib/puzzly_api_plugin/metadata/topic.rb +33 -0
  35. data/lib/puzzly_api_plugin/page.rb +19 -0
  36. data/lib/puzzly_api_plugin/version.rb +5 -0
  37. data/lib/puzzly_api_plugin/view/api.rb +19 -0
  38. data/lib/puzzly_api_plugin/view/apis.rb +23 -0
  39. data/lib/puzzly_api_plugin/view/cache.rb +19 -0
  40. data/lib/puzzly_api_plugin/view/caches.rb +23 -0
  41. data/lib/puzzly_api_plugin/view/context.rb +36 -0
  42. data/lib/puzzly_api_plugin/view/contexts.rb +23 -0
  43. data/lib/puzzly_api_plugin/view/dashboard.rb +32 -0
  44. data/lib/puzzly_api_plugin/view/module.rb +34 -0
  45. data/lib/puzzly_api_plugin/view/modules.rb +23 -0
  46. data/lib/puzzly_api_plugin/view/queries.rb +23 -0
  47. data/lib/puzzly_api_plugin/view/query.rb +19 -0
  48. data/lib/puzzly_api_plugin/view/renderable.rb +57 -0
  49. data/lib/puzzly_api_plugin/view/schema.rb +23 -0
  50. data/lib/puzzly_api_plugin/view/schemas.rb +23 -0
  51. data/lib/puzzly_api_plugin/view/table.rb +19 -0
  52. data/lib/puzzly_api_plugin/view/tables.rb +23 -0
  53. data/lib/puzzly_api_plugin/view/topic.rb +23 -0
  54. data/lib/puzzly_api_plugin/view/topics.rb +23 -0
  55. data/lib/puzzly_api_plugin.rb +55 -0
  56. data/puzzly_api_plugin.gemspec +36 -0
  57. data/script/bootstrap +3 -0
  58. data/script/ci-build +7 -0
  59. data/script/ci-release +15 -0
  60. data/script/fmt +10 -0
  61. data/script/test +4 -0
  62. metadata +201 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ab7afadfc80e147f72a36d7d85903ee358d36f5153825750ebc2d70732aae4f1
4
+ data.tar.gz: f4426b0cf409e74b779cf12019f8a974507cb2ae8e03b17fe91410979ffccbbf
5
+ SHA512:
6
+ metadata.gz: 21c4a4c57638f088ce382caeca5083db6fe525f517c22e31b252594efe46ce75bddb719204ff64b4a1a12922eddd9d520d09c7a1186aeaf2e5606792f487deb0
7
+ data.tar.gz: 2843fc7f00edbe5bcaadec2ba5ab093b4bc915f35129f52f2f19293ccc7e07d5ce8630912b5be9d96fde2684a4dec8f8ba5430230b459bc61ed5c692d45a99b0
@@ -0,0 +1,43 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby
6
+
7
+ working_directory: ~/repo
8
+
9
+ steps:
10
+ - checkout
11
+ - run: "sh ./script/ci-build"
12
+ - save_cache:
13
+ key: gem-cache-{{ .Branch }}-{{ .Revision }}
14
+ paths:
15
+ - vendor/bundle
16
+
17
+ release:
18
+ docker:
19
+ - image: circleci/ruby
20
+
21
+ working_directory: ~/repo
22
+
23
+ steps:
24
+ - checkout
25
+ - add_ssh_keys
26
+ - restore_cache:
27
+ keys:
28
+ - gem-cache-{{ .Branch }}-{{ .Revision }}
29
+ - run: "sh ./script/ci-release"
30
+
31
+ workflows:
32
+ version: 2
33
+ build-deploy:
34
+ jobs:
35
+ - build:
36
+ context: Archmix
37
+ - release:
38
+ context: Archmix
39
+ requires:
40
+ - build
41
+ filters:
42
+ branches:
43
+ only: master
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
14
+
15
+ **/.jekyll-cache
16
+ **/dest
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,11 @@
1
+ Style/Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/ParameterLists:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 200
9
+
10
+ Metrics/AbcSize:
11
+ Max: 20
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in puzzly-generator.gemspec
6
+ gemspec
7
+
8
+ gem 'jekyll', ENV['JEKYLL_VERSION'] if ENV['JEKYLL_VERSION']
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Braz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ sudo apt install build-essential ruby ruby-dev
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # PuzzlyApiPlugin
2
+
3
+ This Gem collect all metadata stored in the Archmix Puzzly Portal and generate all json needed for UI to work.
4
+
5
+ ## Development
6
+
7
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
8
+
9
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
10
+
11
+ ## Contributing
12
+
13
+ Bug reports and pull requests are welcome on GitHub at https://github.com/archmix/puzzly-generator.
14
+
15
+ ## License
16
+
17
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'puzzly/generator'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class ApisCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ api = Api.create document
9
+ add_metadata api
10
+ end
11
+
12
+ def get_by_modules(modules)
13
+ select { |_id, api| modules.key?(api.module_id) }
14
+ end
15
+
16
+ def get_by_module(mod)
17
+ select { |_id, api| mod.id <=> api.module_id }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class CachesCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ cache = Cache.create(document)
9
+ add_metadata cache
10
+ end
11
+
12
+ def get_by_modules(modules)
13
+ select { |_id, cache| modules.key?(cache.module_id) }
14
+ end
15
+
16
+ def get_by_module(mod)
17
+ select { |_id, cache| mod.id <=> cache.module_id }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Collection < JSONable
5
+ def identities
6
+ identities = []
7
+
8
+ each do |_id, metadata|
9
+ identity = metadata.to_identity
10
+ identities.push identity
11
+ end
12
+
13
+ identities
14
+ end
15
+
16
+ def add_metadata(metadata)
17
+ self[metadata.id] = metadata
18
+ end
19
+
20
+ def get_by_id(id)
21
+ self[id]
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class ContextsCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ context = Context.create(document)
9
+ add_metadata context
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class ModulesCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ mod = Module.create(document)
9
+ add_metadata mod
10
+ end
11
+
12
+ def get_by_context(context)
13
+ select { |_id, mod| mod.context_id <=> context.id }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class QueriesCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ query = Query.create(document)
9
+ add_metadata query
10
+ end
11
+
12
+ def get_by_modules(modules)
13
+ select { |_id, query| modules.key?(query.module_id) }
14
+ end
15
+
16
+ def get_by_module(mod)
17
+ select { |_id, query| mod.id <=> query.module_id }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class SchemasCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ schema = Schema.create(document)
9
+ add_metadata schema
10
+ end
11
+
12
+ def get_by_context(context)
13
+ select { |_id, schema| schema.context_id <=> context.id }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class TablesCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ table = Table.create(document)
9
+ add_metadata table
10
+ end
11
+
12
+ def get_by_modules(modules)
13
+ select { |_id, table| modules.key?(table.module_id) }
14
+ end
15
+
16
+ def get_by_module(mod)
17
+ select { |_id, table| mod.id <=> table.module_id }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class TopicsCollection < Collection
5
+ include Singleton
6
+
7
+ def add(document)
8
+ topic = Topic.create(document)
9
+ add_metadata topic
10
+ end
11
+
12
+ def get_by_modules modules
13
+ select { |_id, topic| modules.key?(topic.module_id) }
14
+ end
15
+
16
+ def get_by_module mod
17
+ select { |_id, topic| mod.id <=> topic.module_id }
18
+ end
19
+
20
+ def get_by_schema schema
21
+ select { |_id, topic| schema.id <=> topic.schema_id }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class MetadataFields
5
+ ID = 'id'
6
+ NAME = 'name'
7
+ PATH = 'path'
8
+ DESCRIPTION = 'description'
9
+ SPECIFICATION = 'specification'
10
+ CONTEXT_ID = 'contextId'
11
+ MODULE_ID = 'moduleId'
12
+ SCHEMA_ID = 'schemaId'
13
+
14
+ SUMMARY = 'summary'
15
+ CONTEXT = 'context'
16
+ MODULE = 'module'
17
+ SCHEMA = 'schema'
18
+
19
+ APIS = 'apis'
20
+ NUMBER_OF_APIS = 'numberOfApis'
21
+
22
+ CACHES = 'caches'
23
+ NUMBER_OF_CACHES = 'numberOfCaches'
24
+
25
+ CONTEXTS = 'contexts'
26
+ NUMBER_OF_CONTEXTS = 'numberOfContexts'
27
+
28
+ MODULES = 'modules'
29
+ NUMBER_OF_MODULES = 'numberOfModules'
30
+
31
+ QUERIES = 'queries'
32
+ NUMBER_OF_QUERIES = 'numberOfQueries'
33
+
34
+ SCHEMAS = 'schemas'
35
+ NUMBER_OF_SCHEMAS = 'numberOfSchemas'
36
+
37
+ TABLES = 'tables'
38
+ NUMBER_OF_TABLES = 'numberOfTables'
39
+
40
+ TOPICS = 'topics'
41
+ NUMBER_OF_TOPICS = 'numberOfTopics'
42
+ end
43
+
44
+ class YAMLFields
45
+ API_ID = 'apiId'
46
+ API_NAME = 'apiName'
47
+ API_DESCRIPTION = 'apiDescription'
48
+ API_SPECIFICATION = 'apiSpecification'
49
+
50
+ CACHE_ID = 'cacheId'
51
+ CACHE_NAME = 'cacheName'
52
+ CACHE_DESCRIPTION = 'cacheDescription'
53
+ CACHE_SPECIFICATION = 'cacheSpecification'
54
+
55
+ CONTEXT_ID = 'contextId'
56
+ CONTEXT_NAME = 'contextName'
57
+ CONTEXT_DESCRIPTION = 'contextDescription'
58
+
59
+ MODULE_ID = 'moduleId'
60
+ MODULE_NAME = 'moduleName'
61
+ MODULE_DESCRIPTION = 'moduleDescription'
62
+
63
+ QUERY_ID = 'queryId'
64
+ QUERY_NAME = 'queryName'
65
+ QUERY_DESCRIPTION = 'queryDescription'
66
+ QUERY_SPECIFICATION = 'querySpecification'
67
+
68
+ SCHEMA_ID = 'schemaId'
69
+ SCHEMA_NAME = 'schemaName'
70
+ SCHEMA_DESCRIPTION = 'schemaDescription'
71
+ SCHEMA_SPECIFICATION = 'schemaSpecification'
72
+
73
+ TABLE_ID = 'tableId'
74
+ TABLE_NAME = 'tableName'
75
+ TABLE_DESCRIPTION = 'tableDescription'
76
+ TABLE_SPECIFICATION = 'tableSpecification'
77
+
78
+ TOPIC_ID = 'topicId'
79
+ TOPIC_NAME = 'topicName'
80
+ TOPIC_DESCRIPTION = 'topicDescription'
81
+ end
82
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Generator < Jekyll::Generator
5
+ safe true
6
+
7
+ def generate(site)
8
+ site.documents.each do |document|
9
+ collection = PuzzlyApiPlugin.const_get("#{document.collection.label.capitalize}Collection").instance
10
+ collection.add(document)
11
+ end
12
+
13
+ render site, HomeDashboardView.create
14
+
15
+ render site, ContextsView.create
16
+ ContextsCollection.instance.values.each do |context|
17
+ render site, ContextView.create(context)
18
+ end
19
+
20
+ render site, ModulesView.create
21
+ ModulesCollection.instance.values.each do |mod|
22
+ render site, ModuleView.create(mod)
23
+ end
24
+
25
+ render site, SchemasView.create
26
+ SchemasCollection.instance.values.each do |schema|
27
+ render site, SchemaView.create(schema)
28
+ end
29
+
30
+ render site, ApisView.create
31
+ ApisCollection.instance.values.each do |api|
32
+ render site, ApiView.create(api)
33
+ end
34
+
35
+ render site, CachesView.create
36
+ CachesCollection.instance.values.each do |cache|
37
+ render site, CacheView.create(cache)
38
+ end
39
+
40
+ render site, QueriesView.create
41
+ QueriesCollection.instance.values.each do |query|
42
+ render site, QueryView.create(query)
43
+ end
44
+
45
+ render site, TablesView.create
46
+ TablesCollection.instance.values.each do |table|
47
+ render site, TableView.create(table)
48
+ end
49
+
50
+ render site, TopicsView.create
51
+ TopicsCollection.instance.values.each do |topic|
52
+ render site, TopicView.create(topic)
53
+ end
54
+ end
55
+
56
+ def render(site, view)
57
+ content = view.render
58
+ path = view.path
59
+ site.pages << JSONPage.new(site, site.source, File.dirname(path), File.basename(path), content)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Identity < JSONable
5
+ def self.create(metadata)
6
+ Identity.new(metadata.id, metadata.name, metadata.path)
7
+ end
8
+
9
+ def initialize(id, name, path)
10
+ self['id'] = id
11
+ self['name'] = name
12
+ self['path'] = path
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class JSONable < Hash
5
+ def copy_to_hash(hash)
6
+ each do |key, value|
7
+ hash.store(key, value)
8
+ end
9
+ end
10
+
11
+ def to_s
12
+ to_json
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Api < Metadata
5
+ def self.create(document)
6
+ Api.new(document,
7
+ document.data[YAMLFields::MODULE_ID],
8
+ document.data[YAMLFields::API_ID],
9
+ document.data[YAMLFields::API_NAME],
10
+ document.data[YAMLFields::API_DESCRIPTION],
11
+ document.data[YAMLFields::API_SPECIFICATION])
12
+ end
13
+
14
+ def initialize(document, module_id, id, name, description, specification)
15
+ super(document, id, name)
16
+ self[MetadataFields::MODULE_ID] = module_id
17
+ self[MetadataFields::DESCRIPTION] = description
18
+ self[MetadataFields::SPECIFICATION] = specification
19
+ end
20
+
21
+ def module_id
22
+ self[MetadataFields::MODULE_ID]
23
+ end
24
+
25
+ def description
26
+ self[MetadataFields::DESCRIPTION]
27
+ end
28
+
29
+ def specification
30
+ self[MetadataFields::SPECIFICATION]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Cache < Metadata
5
+ def self.create(document)
6
+ Cache.new(document,
7
+ document.data[YAMLFields::MODULE_ID],
8
+ document.data[YAMLFields::CACHE_ID],
9
+ document.data[YAMLFields::CACHE_NAME],
10
+ document.data[YAMLFields::CACHE_DESCRIPTION],
11
+ document.data[YAMLFields::CACHE_SPECIFICATION])
12
+ end
13
+
14
+ def initialize(document, module_id, id, name, description, specification)
15
+ super(document, id, name)
16
+ self[MetadataFields::MODULE_ID] = module_id
17
+ self[MetadataFields::DESCRIPTION] = description
18
+ self[MetadataFields::SPECIFICATION] = specification
19
+ end
20
+
21
+ def module_id
22
+ self[MetadataFields::MODULE_ID]
23
+ end
24
+
25
+ def description
26
+ self[MetadataFields::DESCRIPTION]
27
+ end
28
+
29
+ def specification
30
+ self[MetadataFields::SPECIFICATION]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Context < Metadata
5
+ def self.create(document)
6
+ Context.new(document,
7
+ document.data[YAMLFields::CONTEXT_ID],
8
+ document.data[YAMLFields::CONTEXT_NAME],
9
+ document.data[YAMLFields::CONTEXT_DESCRIPTION])
10
+ end
11
+
12
+ def initialize(document, id, name, description)
13
+ super(document, id, name)
14
+ self[MetadataFields::DESCRIPTION] = description
15
+ end
16
+
17
+ def description
18
+ self[MetadataFields::DESCRIPTION]
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Metadata < JSONable
5
+ def initialize(document, id, name)
6
+ self[MetadataFields::PATH] = document.collection.label.to_s + document.cleaned_relative_path
7
+ self[MetadataFields::ID] = id
8
+ self[MetadataFields::NAME] = name
9
+ end
10
+
11
+ def path
12
+ self[MetadataFields::PATH]
13
+ end
14
+
15
+ def id
16
+ self[MetadataFields::ID]
17
+ end
18
+
19
+ def name
20
+ self[MetadataFields::NAME]
21
+ end
22
+
23
+ def to_identity
24
+ Identity.create(self)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuzzlyApiPlugin
4
+ class Module < Metadata
5
+ def self.create(document)
6
+ Module.new(document,
7
+ document.data[YAMLFields::CONTEXT_ID],
8
+ document.data[YAMLFields::MODULE_ID],
9
+ document.data[YAMLFields::MODULE_NAME],
10
+ document.data[YAMLFields::MODULE_DESCRIPTION])
11
+ end
12
+
13
+ def initialize(document, context_id, id, name, description)
14
+ super(document, id, name)
15
+ self[MetadataFields::CONTEXT_ID] = context_id
16
+ self[MetadataFields::DESCRIPTION] = description
17
+ end
18
+
19
+ def context_id
20
+ self[MetadataFields::CONTEXT_ID]
21
+ end
22
+
23
+ def description
24
+ self[MetadataFields::DESCRIPTION]
25
+ end
26
+ end
27
+ end