beze-gena 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c894006f9bafc1fce1621e9d6d1c3e6cf58aa534ec40acfa5789c743b0da539
4
+ data.tar.gz: 4fba6aafa7209f521ba9a245d0532c5acbbbc4edbeb5410ccdcfc962ff431776
5
+ SHA512:
6
+ metadata.gz: b13b1b328c066e64052f23e3dd646d2bb37259cc2351fff2e5ab2b57188295361de7fa6bdf774d4d98d56e1af5182b0340166d099c04b0bfebdac8a34dce26a4
7
+ data.tar.gz: 35f427df8b9f95f265dc318c9681ee095d9ed35bffdf754521972b864b0bea3ff2baadc31313f6132d6f2c83b327f8df3c1e7c98d9e9d84742f8cf71fb629f67
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Metrics/MethodLength:
16
+ Max: 20
17
+
18
+ Metrics/AbcSize:
19
+ Enabled: false
20
+
21
+ Metrics/ParameterLists:
22
+ Max: 10
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-04-20
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in beze-gena.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ beze-gena (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ parallel (1.22.1)
12
+ parser (3.1.2.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.1.1)
15
+ rake (13.0.6)
16
+ regexp_parser (2.3.0)
17
+ rexml (3.2.5)
18
+ rspec (3.11.0)
19
+ rspec-core (~> 3.11.0)
20
+ rspec-expectations (~> 3.11.0)
21
+ rspec-mocks (~> 3.11.0)
22
+ rspec-core (3.11.0)
23
+ rspec-support (~> 3.11.0)
24
+ rspec-expectations (3.11.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.11.0)
27
+ rspec-mocks (3.11.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-support (3.11.0)
31
+ rubocop (1.27.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.1.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.16.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.17.0)
41
+ parser (>= 3.1.1.0)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.1.0)
44
+
45
+ PLATFORMS
46
+ x86_64-darwin-21
47
+ x86_64-linux
48
+
49
+ DEPENDENCIES
50
+ beze-gena!
51
+ rake (~> 13.0)
52
+ rspec (~> 3.0)
53
+ rubocop (~> 1.21)
54
+
55
+ BUNDLED WITH
56
+ 2.3.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Sylvance
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.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Beze::Gena
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/beze/gena`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add beze-gena
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install beze-gena
16
+
17
+ ## Usage
18
+
19
+ To use this do;
20
+
21
+ ```ruby
22
+ Beze::Gena.configure do |configuration|
23
+ path_template = 'users/app/template'
24
+ path_json_data = 'users/app/json'
25
+ path_scrape_data = 'users/app/scrape'
26
+ path_target = 'users/app/target'
27
+ end
28
+ Beze::Gena.generate
29
+ ```
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
36
+
37
+ To add linux build for gems do `bundle lock --add-platform x86_64-linux`.
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Sylvance/beze-gena.
42
+
43
+ ## License
44
+
45
+ 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,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/beze-gena.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/beze/gena/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "beze-gena"
7
+ spec.version = Beze::Gena::VERSION
8
+ spec.authors = ["Sylvance"]
9
+ spec.email = ["103753399+ninjawork@users.noreply.github.com"]
10
+
11
+ spec.summary = "Spicy beze generator"
12
+ spec.description = "Spicy beze generator"
13
+ spec.homepage = "https://github.com/bezefy/beze-gena"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/bezefy/beze-gena"
21
+ spec.metadata["changelog_uri"] = "https://github.com/bezefy/beze-gena/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ # Ruby gem that helps you generate code files.
6
+ module Beze
7
+ module Gena
8
+ class Builder
9
+ include ERB::Util
10
+
11
+ attr_accessor :class_name, :items, :target, :template, :version
12
+
13
+ def self.call(class_name:, items:, target:, template:, version:)
14
+ new(class_name, items, target, template, version).save
15
+ end
16
+
17
+ def initialize(class_name, items, target, template, version)
18
+ @class_name = class_name
19
+ @items = items
20
+ @target = target
21
+ @template = template
22
+ @version = version
23
+ end
24
+
25
+ def call
26
+ File.open(target, "w+") do |f|
27
+ f.write(render)
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def render
34
+ ERB.new(template).result(binding)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "runner"
4
+
5
+ # Ruby gem that helps you generate files from templates.
6
+ module Beze
7
+ module Gena
8
+ # Run class to introduce generated classes.
9
+ class Generator
10
+ def self.run
11
+ new.run
12
+ end
13
+
14
+ def initialize; end
15
+
16
+ def run
17
+ hash.each do |api_module|
18
+ link = api_module[:link]
19
+ name = api_module[:name]
20
+ version = api_module[:version]
21
+
22
+ Beze::Gena::Runner.run(link: link, name: name, version: version)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def hash
29
+ JSON.parse(File.read(Beze::Gena.configuration.path_scrape_data))
30
+ end
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "net/http"
5
+ require "openssl"
6
+ require "ostruct"
7
+ require "json"
8
+
9
+ # Ruby gem that helps to generate files..
10
+ module Beze
11
+ module Gena
12
+ # Http client that acts as a middleman to the API.
13
+ class HttpClient
14
+ NET_HTTP_ERRORS = [
15
+ Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError,
16
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
17
+ JSON::ParserError, SocketError
18
+ ].freeze
19
+
20
+ def self.call(method:, uri:, body: nil, params: nil, headers: nil, auth: nil, expect: nil)
21
+ new(method, uri, body, params, headers, auth, expect).call
22
+ end
23
+
24
+ def initialize(method, uri, body, params, headers, auth, expect)
25
+ @method = method
26
+ @body = body
27
+ @headers = headers
28
+ @auth = auth
29
+ @url = prepare_uri(uri, params)
30
+ @expect = expect.nil? ? :json : expect
31
+ @http = prepare_http
32
+ @request = prepare_request
33
+ end
34
+
35
+ def call
36
+ response
37
+ end
38
+
39
+ private
40
+
41
+ attr_accessor :auth, :body, :expect, :headers, :http, :method, :request, :url
42
+
43
+ def response
44
+ http_response = http.request(request)
45
+
46
+ if http_response.is_a?(Net::HTTPSuccess)
47
+ result = Beze::Gena.to_ostruct(JSON.parse(http_response.read_body)) if expect == :json
48
+ result = http_response.read_body if expect == :html
49
+ result_struct(result, http_response, true)
50
+ else
51
+ result_struct(nil, http_response, false)
52
+ end
53
+ rescue *NET_HTTP_ERRORS => e
54
+ result_struct(e, http_response, false)
55
+ end
56
+
57
+ def result_struct(result, response, success)
58
+ OpenStruct.new(
59
+ result: result,
60
+ headers: Beze::Gena.to_ostruct(response.to_hash),
61
+ code: response.code,
62
+ message: response.message,
63
+ class: response.class.name,
64
+ successful?: success
65
+ )
66
+ end
67
+
68
+ def prepare_uri(uri, params)
69
+ build_url = URI(uri)
70
+ build_url.query = URI.encode_www_form(params) unless params.nil?
71
+ build_url
72
+ end
73
+
74
+ def prepare_http
75
+ protocol = Net::HTTP.new(url.host, url.port)
76
+ protocol.use_ssl = true
77
+ protocol.verify_mode = OpenSSL::SSL::VERIFY_NONE
78
+ protocol
79
+ end
80
+
81
+ def prepare_request
82
+ req = build_request
83
+ req.basic_auth(auth[:user], auth[:password]) unless auth.nil?
84
+ req.body = JSON.dump(body) unless body.nil?
85
+ req
86
+ end
87
+
88
+ def build_request
89
+ return Net::HTTP::Get.new(url, headers) if method == :get
90
+ return Net::HTTP::Post.new(url, headers) if method == :post
91
+ return Net::HTTP::Put.new(url, headers) if method == :put
92
+ return Net::HTTP::Patch.new(url, headers) if method == :patch
93
+ return Net::HTTP::Delete.new(url, headers) if method == :delete
94
+ return Net::HTTP::Options.new(url, headers) if method == :options
95
+ end
96
+ end
97
+ end
98
+ end
99
+
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ruby gem that helps you generate files.
4
+ module Beze
5
+ module Gena
6
+ class Items
7
+ attr_accessor :json_spec_result, :version
8
+
9
+ def self.items(json_spec_result:, version:)
10
+ new(json_spec_result, version).items
11
+ end
12
+
13
+ def initialize(json_spec_result, version)
14
+ @json_spec_result = json_spec_result
15
+ @version = version
16
+ end
17
+
18
+ def items
19
+ collection = []
20
+
21
+ json_spec_result.each do |block|
22
+ fields = block.except("namespace_description", "method", "endpoint")
23
+ values = values_from(fields)
24
+ collection << api_hash_for(block, values)
25
+ end
26
+
27
+ collection
28
+ end
29
+
30
+ def values_from(fields)
31
+ auth = []
32
+ body = []
33
+ documentation = []
34
+ headers = []
35
+ params = []
36
+ params_flat = []
37
+ params_kv = []
38
+ params_kv_no_nil = []
39
+
40
+ fields.each do |_, value|
41
+ auth << get_auth_from(value) if value["field_type"] == "auth"
42
+ body << get_body_from(value) if value["field_type"] == "body"
43
+ documentation << get_docu_from(value) if %w[body path].include?(value["field_type"])
44
+ headers << get_headers_from(value) if value["field_type"] == "header"
45
+ params << get_params_from(value) if value["field_type"] == "query"
46
+ params_flat << get_params_flat_from(value) if %w[body path].include?(value["field_type"])
47
+ params_kv << get_params_kv_from(value) if %w[body path].include?(value["field_type"])
48
+ params_kv_no_nil << get_params_kv_no_nil_from(value) if %w[body path].include?(value["field_type"])
49
+ end
50
+
51
+ {
52
+ auth: auth, body: body, documentation: documentation, headers: headers,
53
+ params: params, params_flat: params_flat, params_kv: params_kv, params_kv_no_nil: params_kv_no_nil
54
+ }
55
+ end
56
+
57
+ def get_auth_from(value)
58
+ "#{value["fields"]["name"]}: #{value["fields"]["name"]}"
59
+ end
60
+
61
+ def get_body_from(value)
62
+ "#{value["fields"]["name"]}: #{value["fields"]["name"]}"
63
+ end
64
+
65
+ def get_docu_from(value)
66
+ "# @param #{value["fields"]["name"]} [#{value["fields"]["type"].capitalize}] #{value["fields"]["description"]}"
67
+ end
68
+
69
+ def get_headers_from(value)
70
+ if value["fields"]["name"] == "accept"
71
+ "#{value["fields"]["name"]}: 'application/vnd.github.v#{version}+json'"
72
+ else
73
+ "#{value["fields"]["name"]}: #{value["fields"]["name"]}"
74
+ end
75
+ end
76
+
77
+ def get_params_from(value)
78
+ "#{value["fields"]["name"]}: options[:#{value["fields"]["name"]}]"
79
+ end
80
+
81
+ def get_params_flat_from(value)
82
+ value["fields"]["name"].to_s
83
+ end
84
+
85
+ def get_params_kv_from(value)
86
+ "#{value["fields"]["name"]}: nil"
87
+ end
88
+
89
+ def get_params_kv_no_nil_from(value)
90
+ "#{value["fields"]["name"]}: #{value["fields"]["name"]}"
91
+ end
92
+
93
+ def api_hash_for(block, values)
94
+ api_hash = {}
95
+ api_hash["http_method"] = block["method"]
96
+ api_hash["endpoint"] = block["endpoint"].gsub("{", '#{')
97
+ api_hash["description"] = block["namespace_description"].downcase
98
+ api_hash["method_name"] = block["namespace_description"].downcase.gsub("-", "_").split(" ").join("_")
99
+ api_hash["auth"] = values[:auth].size.zero? ? "nil" : "{ #{values[:auth].join(", ")} }"
100
+ api_hash["body"] = values[:body].size.zero? ? "nil" : "{ #{values[:body].join(", ")} }"
101
+ api_hash["documentation"] = values[:documentation].size.zero? ? "# @params options [Hash]" : values[:documentation].join("\n\t\t\t\t")
102
+ api_hash["headers"] = values[:headers].size.zero? ? "nil" : "{ #{values[:headers].join(", ")} }"
103
+ api_hash["params"] = values[:params].size.zero? ? "nil" : "{ #{values[:params].join(", ")} }"
104
+ api_hash["path_params_flat"] = values[:params_flat].size.zero? ? "(options)" : "(#{values[:params_flat].join(", ")}, options)"
105
+ api_hash["params_key_value"] = values[:params_kv].size.zero? ? "(options: nil)" : "(#{values[:params_kv].join(", ")}, options: nil)"
106
+ api_hash["params_key_value_without_nil"] = values[:params_kv_no_nil].size.zero? ? "options: options)" : "(#{values[:params_kv_no_nil].join(", ")}, options: nil)"
107
+ api_hash
108
+ end
109
+ end
110
+ end
111
+ end
112
+
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "fileutils"
5
+
6
+ require_relative "builder"
7
+ require_relative "items"
8
+ require_relative "scraper"
9
+
10
+ # Ruby gem that helps you generate files from templates.
11
+ module Beze
12
+ module Gena
13
+ # Run class to introduce generated classes.
14
+ class Runner
15
+ attr_accessor :link, :name, :version
16
+
17
+ def self.run(link:, name:, version:)
18
+ new(link, name, version).run
19
+ end
20
+
21
+ def initialize(link, name, version)
22
+ @link = link
23
+ @name = name
24
+ @version = version
25
+ end
26
+
27
+ def run
28
+ generate_json_spec
29
+ generate_target_file
30
+ end
31
+
32
+ private
33
+
34
+ def generate_json_spec
35
+ Beze::Gena::Scraper.scrape(link: link, name: name, version: version)
36
+ end
37
+
38
+ def generate_target_file
39
+ Beze::Gena::Builder.call(
40
+ class_name: name.capitalize, items: items, target: target, template: template, version: version
41
+ )
42
+ end
43
+
44
+ def items
45
+ Beze::Gena::Items.items(json_spec_result: json_spec_result, version: version)
46
+ end
47
+
48
+ def target
49
+ ensure_target_folder_created
50
+ "#{Beze::Gena.configuration.path_target}/#{name}.#{extension}"
51
+ end
52
+
53
+ def template
54
+ File.read(Beze::Gena.configuration.path_template)
55
+ end
56
+
57
+ def json_spec_result
58
+ data = JSON.parse(File.read(json_spec))
59
+ data["result"]
60
+ end
61
+
62
+ def ensure_target_folder_created
63
+ FileUtils.mkdir_p(Beze::Gena.configuration.path_target)
64
+ end
65
+
66
+ def json_spec
67
+ "#{Beze::Gena.configuration.path_json_data}/#{name}.json"
68
+ end
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "fileutils"
4
+ require "json"
5
+ require "nokogiri"
6
+ require "ostruct"
7
+
8
+ require_relative "http_client"
9
+
10
+ # Ruby gem that helps you generate files from templates.
11
+ module Beze
12
+ module Gena
13
+ # Scraper that gets link to Github API and returns endpoints as variables.
14
+ class Scraper
15
+ attr_accessor :link, :name, :version
16
+
17
+ def self.scrape(link:, name:, version:)
18
+ new(link, name, version).scrape
19
+ end
20
+
21
+ def initialize(link, name, version)
22
+ @link = link
23
+ @name = name
24
+ @version = version
25
+ end
26
+
27
+ def scrape
28
+ hash = { result: list }
29
+
30
+ FileUtils.mkdir_p("#{Beze::Gena.configuration.path_json_data}")
31
+ FileUtils.touch("#{Beze::Gena.configuration.path_json_data}/#{name}.json")
32
+ File.open("#{Beze::Gena.configuration.path_json_data}/#{name}.json", "w") do |f|
33
+ f.write(JSON.pretty_generate(hash))
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def list
40
+ page = download_link_page
41
+ document = parse(page)
42
+
43
+ table_list(document)
44
+ end
45
+
46
+ def download_link_page
47
+ Beze::Gena::HttpClient.call(method: :get, uri: link, expect: :html).result
48
+ end
49
+
50
+ def parse(page)
51
+ Nokogiri::HTML(page)
52
+ end
53
+
54
+ def table_list(document)
55
+ [document]
56
+ end
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Beze
4
+ module Gena
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
data/lib/beze/gena.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "gena/builder"
4
+ require_relative "gena/generator"
5
+ require_relative "gena/items"
6
+ require_relative "gena/runner"
7
+ require_relative "gena/scraper"
8
+ require_relative "gena/version"
9
+
10
+ module Beze
11
+ module Gena
12
+ def self.configure
13
+ yield configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= OpenStruct.new(
18
+ path_template: nil, path_json_data: nil, path_scrape_data: nil, path_target: nil
19
+ )
20
+ end
21
+
22
+ def self.generate
23
+ Beze::Gena::Generator.call
24
+ end
25
+
26
+ def self.to_ostruct(input)
27
+ result = {}
28
+
29
+ if input.is_a?(Hash)
30
+ result["type"] = input.class
31
+ result["keys"] = input.keys
32
+
33
+ input.each do |key, value|
34
+ result[key] = hash_or_array(value) ? to_ostruct(value) : OpenStruct.new(value: value, type: value.class)
35
+ end
36
+ end
37
+
38
+ if input.is_a?(Array)
39
+ result["type"] = input.class
40
+ result["size"] = input.size
41
+
42
+ input.each.with_index do |value, index|
43
+ result["value_at_#{index}"] =
44
+ hash_or_array(value) ? to_ostruct(value) : OpenStruct.new(value: value, type: value.class)
45
+ end
46
+ end
47
+
48
+ OpenStruct.new(result)
49
+ end
50
+
51
+ def self.hash_or_array(val)
52
+ val.is_a?(Hash) || val.is_a?(Array)
53
+ end
54
+ end
55
+ end
56
+
data/sig/beze/gena.rbs ADDED
@@ -0,0 +1,6 @@
1
+ module Beze
2
+ module Gena
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beze-gena
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sylvance
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Spicy beze generator
14
+ email:
15
+ - 103753399+ninjawork@users.noreply.github.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".rspec"
21
+ - ".rubocop.yml"
22
+ - CHANGELOG.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - beze-gena.gemspec
29
+ - lib/beze/gena.rb
30
+ - lib/beze/gena/builder.rb
31
+ - lib/beze/gena/generator.rb
32
+ - lib/beze/gena/http_client.rb
33
+ - lib/beze/gena/items.rb
34
+ - lib/beze/gena/runner.rb
35
+ - lib/beze/gena/scraper.rb
36
+ - lib/beze/gena/version.rb
37
+ - sig/beze/gena.rbs
38
+ homepage: https://github.com/bezefy/beze-gena
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ allowed_push_host: https://rubygems.org
43
+ homepage_uri: https://github.com/bezefy/beze-gena
44
+ source_code_uri: https://github.com/bezefy/beze-gena
45
+ changelog_uri: https://github.com/bezefy/beze-gena/blob/main/CHANGELOG.md
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.2.22
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: Spicy beze generator
65
+ test_files: []