webamm 0.0.1 → 0.0.2

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: 1a81a8cc8c018322fb2bcf049222a341b0cecd1ddd064338f514272129034530
4
- data.tar.gz: 189fab49524efcbcfa11774cf010fd4675d6b886a52436b832e836311ea74a67
3
+ metadata.gz: f29111980d6d9c0f7e0b558ff41670d3df28fc7c4fe33d937fd277abbf4d660f
4
+ data.tar.gz: 54c7aaa6d7c86aea4af69cbfb41e43c510473b9cca2ab9344fb705143740ea4b
5
5
  SHA512:
6
- metadata.gz: 3520ae29d246369963ce4b5e4b9df076654af0796a0092b8ec558161f7d5b410c7ce56cf457ea91e54eb612a0de594ae03abfd872bd400530a4c69f0b4569a21
7
- data.tar.gz: cf819a792a6744c51b0e34cafeffd688e8f0fe623fb8ed81139b49945f23fd67e4bb260f4ddf756eee757efaedf2885711ae1bb2011e2e35c1b5f7397b33331f
6
+ metadata.gz: '05942127b2264ded31f5d39399b13ab86f4b7a52cd98293109f734457687c4d6b6bca5b3f7fa98c874f4c103902195e0edf9b5fe61c0ec713a483405f077560b'
7
+ data.tar.gz: cd10cacf09435d2146c4c3fb3787005750f48cf5f4b3260ee90ac76d15690892f2de0dd010dda6e44a489f7653d2e9c10adeae1be314a973fdf0981f58d24f76
data/bin/webamm ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'webamm'
5
+
6
+ command_line_arguments = ARGV.dup
7
+
8
+ Webamm::Cli::Processor.new(command_line_arguments).call
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Webamm
4
+ module Cli
5
+ class FetchTemplate
6
+ API_HOST = 'https://app.webamm.org'
7
+
8
+ def call(uid)
9
+ api_url = ENV.fetch('API_HOST', API_HOST)
10
+ response = RestClient.get(api_url + "/api/v1/plans/#{uid}") { |res| res }
11
+
12
+ return if response.code != 200
13
+
14
+ JSON.parse(response.body)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Webamm
4
+ module Cli
5
+ class Processor
6
+ COMMANDS = %w[build].freeze
7
+
8
+ InvalidCommand = Class.new(StandardError)
9
+ InvalidUid = Class.new(StandardError)
10
+
11
+ def initialize(args)
12
+ @command = args[0]
13
+ @uid = args[1]
14
+ end
15
+
16
+ def call
17
+ validate_command
18
+
19
+ raise InvalidUid, "Plan not found for #{@uid}" if json_template.nil?
20
+
21
+ ::Webamm.build(json_template)
22
+ end
23
+
24
+ private
25
+
26
+ def validate_command
27
+ raise InvalidCommand, "command #{@command} is not supported!" unless COMMANDS.include?(@command.to_s.downcase)
28
+ end
29
+
30
+ def json_template
31
+ return @json_template if defined?(@json_template)
32
+
33
+ @json_template = ::Webamm::Cli::FetchTemplate.new.call(@uid)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Webamm
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
data/lib/webamm.rb CHANGED
@@ -5,6 +5,13 @@ module Types
5
5
  StrongString = String.constructor(->(val){ val.to_s })
6
6
  end
7
7
 
8
+ require 'rest-client'
9
+ require 'json'
10
+ require 'fileutils'
11
+
12
+ require_relative 'webamm/cli/fetch_template'
13
+ require_relative 'webamm/cli/processor'
14
+
8
15
  require_relative 'webamm/database/schema/column'
9
16
  require_relative 'webamm/database/schema/index'
10
17
  require_relative 'webamm/authentication'
@@ -30,4 +37,21 @@ module Webamm
30
37
  attribute :relationships, Types::Array.of(Webamm::Database::Relationship).default([].freeze)
31
38
  end
32
39
  end
40
+
41
+ class << self
42
+ def build(files)
43
+ dir_name = "webamm_app-#{Time.now.strftime('%Y%m%d%H%M%S')}"
44
+ FileUtils.mkdir_p(dir_name)
45
+ Dir.chdir(dir_name)
46
+
47
+ files.each do |file|
48
+ puts "-> \e[1;32;49mCreate\e[0m #{file['path']}"
49
+ file_path = File.join(Dir.pwd, file['path'])
50
+ FileUtils.mkdir_p(File.dirname(file_path))
51
+ File.write(file_path, file['content'])
52
+ end
53
+
54
+ FileUtils.chmod_R("u+x", './bin')
55
+ end
56
+ end
33
57
  end
data/webamm.gemspec CHANGED
@@ -12,8 +12,11 @@ Gem::Specification.new do |spec|
12
12
  spec.version = Webamm::VERSION.dup
13
13
  spec.summary = 'Web Application Metadata Markup'
14
14
  spec.description = spec.summary
15
- spec.files = Dir['README.md', 'webamm.gemspec', 'lib/**/*']
15
+ spec.files = Dir['README.md', 'webamm.gemspec', 'bin/*', 'lib/**/*']
16
+ spec.bindir = 'bin'
17
+ spec.executables = ['webamm']
16
18
  spec.require_paths = ['lib']
17
19
  spec.add_runtime_dependency 'dry-struct', '1.6.0'
20
+ spec.add_runtime_dependency 'rest-client', '2.1.0'
18
21
  spec.required_ruby_version = '>= 3.2.2'
19
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webamm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paweł Dąbrowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-19 00:00:00.000000000 Z
11
+ date: 2024-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -24,16 +24,34 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.0
27
41
  description: Web Application Metadata Markup
28
42
  email:
29
43
  - contact@paweldabrowski.com
30
- executables: []
44
+ executables:
45
+ - webamm
31
46
  extensions: []
32
47
  extra_rdoc_files: []
33
48
  files:
34
49
  - README.md
50
+ - bin/webamm
35
51
  - lib/webamm.rb
36
52
  - lib/webamm/authentication.rb
53
+ - lib/webamm/cli/fetch_template.rb
54
+ - lib/webamm/cli/processor.rb
37
55
  - lib/webamm/database/crud.rb
38
56
  - lib/webamm/database/relationship.rb
39
57
  - lib/webamm/database/schema/column.rb