legion-cli 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +61 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +17 -0
  6. data/Gemfile +4 -0
  7. data/README.md +3 -0
  8. data/Rakefile +6 -0
  9. data/bitbucket-pipelines.yml +69 -0
  10. data/exe/legionio +4 -0
  11. data/exe/lex_gen +5 -0
  12. data/legion-cli.gemspec +35 -0
  13. data/lib/legion/cli.rb +56 -0
  14. data/lib/legion/cli/chain.rb +36 -0
  15. data/lib/legion/cli/cohort.rb +10 -0
  16. data/lib/legion/cli/function.rb +41 -0
  17. data/lib/legion/cli/lex/actor.rb +31 -0
  18. data/lib/legion/cli/lex/exchange.rb +32 -0
  19. data/lib/legion/cli/lex/message.rb +32 -0
  20. data/lib/legion/cli/lex/queue.rb +32 -0
  21. data/lib/legion/cli/lex/runner.rb +71 -0
  22. data/lib/legion/cli/lex/templates/actor.erb +6 -0
  23. data/lib/legion/cli/lex/templates/actor_spec.erb +0 -0
  24. data/lib/legion/cli/lex/templates/base/bitbucket.yml.erb +69 -0
  25. data/lib/legion/cli/lex/templates/base/gemfile.erb +3 -0
  26. data/lib/legion/cli/lex/templates/base/gemspec.erb +26 -0
  27. data/lib/legion/cli/lex/templates/base/gitignore.erb +11 -0
  28. data/lib/legion/cli/lex/templates/base/lex.erb +9 -0
  29. data/lib/legion/cli/lex/templates/base/lex_spec.erb +5 -0
  30. data/lib/legion/cli/lex/templates/base/lic.erb +21 -0
  31. data/lib/legion/cli/lex/templates/base/rakefile.erb +6 -0
  32. data/lib/legion/cli/lex/templates/base/readme.md.erb +2 -0
  33. data/lib/legion/cli/lex/templates/base/rubocop.yml.erb +15 -0
  34. data/lib/legion/cli/lex/templates/base/spec_helper.rb.erb +11 -0
  35. data/lib/legion/cli/lex/templates/base/version.erb +7 -0
  36. data/lib/legion/cli/lex/templates/exchange.erb +11 -0
  37. data/lib/legion/cli/lex/templates/exchange_spec.erb +0 -0
  38. data/lib/legion/cli/lex/templates/message.erb +27 -0
  39. data/lib/legion/cli/lex/templates/message_spec.erb +0 -0
  40. data/lib/legion/cli/lex/templates/queue.erb +8 -0
  41. data/lib/legion/cli/lex/templates/queue_spec.erb +0 -0
  42. data/lib/legion/cli/lex/templates/runner.erb +11 -0
  43. data/lib/legion/cli/lex/templates/runner_spec.erb +11 -0
  44. data/lib/legion/cli/relationship.rb +22 -0
  45. data/lib/legion/cli/task.rb +49 -0
  46. data/lib/legion/cli/trigger.rb +81 -0
  47. data/lib/legion/cli/version.rb +5 -0
  48. data/lib/legion/lex.rb +91 -0
  49. metadata +176 -0
@@ -0,0 +1,32 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Message < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new message'
18
+ def create(name)
19
+ template('templates/message.erb', "lib/legion/extensions/#{lex}/transport/messages/#{name}.rb", { name: name, lex: lex })
20
+ template('templates/message_spec.erb', "spec/messages/#{name}_spec.rb", { name: name, lex: lex })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes a message class'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/transport/messages/#{name}.rb")
26
+ remove_file("spec/messages/#{name}_spec.rb")
27
+ remove_file("spec/transport/messages/#{name}_spec.rb")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Queue < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'create :name', 'creates a new queue'
18
+ def create(name)
19
+ template('templates/queue.erb', "lib/legion/extensions/#{lex}/transport/queues/#{name}.rb", { name: name, lex: lex })
20
+ template('templates/queue_spec.erb', "spec/queues/#{name}_spec.rb", { name: name, lex: lex })
21
+ end
22
+
23
+ desc 'delete :name', 'deletes a queue config file'
24
+ def delete(name)
25
+ remove_file("lib/legion/extensions/#{lex}/transport/queues/#{name}.rb")
26
+ remove_file("spec/queues/#{name}_spec.rb")
27
+ remove_file("spec/transport/queues/#{name}_spec.rb")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,71 @@
1
+ module Legion
2
+ class Cli
3
+ module Lex
4
+ class Runner < Thor
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ File.dirname(__FILE__)
9
+ end
10
+
11
+ no_commands do
12
+ def lex
13
+ Dir.pwd.split('/').last.split('-').last
14
+ end
15
+ end
16
+
17
+ desc 'delete :runner', 'deletes a runner'
18
+ def delete(name)
19
+ remove_file("lib/legion/extensions/#{lex}/runners/#{name}.rb")
20
+ remove_file("spec/runners/#{name}_spec.rb")
21
+ end
22
+
23
+ desc 'create name type', 'creates a new runner'
24
+ def create(name)
25
+ template('templates/runner.erb', "lib/legion/extensions/#{lex}/runners/#{name}.rb", { name: name, lex: lex })
26
+ template('templates/runner_spec.erb', "spec/runners/#{name}_spec.rb", { name: name, lex: lex })
27
+ end
28
+
29
+ desc 'add_function new_function_name *args', 'adds new function to runner, args optional'
30
+ def add_function(name, function, args = nil)
31
+ @arg_keys = []
32
+
33
+ if args.nil?
34
+ args = '**'
35
+ else
36
+ option_args = ''
37
+ required_args = ''
38
+ args.split(',').each do |arg|
39
+ key, value = arg.split('=')
40
+ @arg_keys.push key.to_s
41
+ if value.nil? || value.empty?
42
+ required_args.concat("#{key}:, ")
43
+ else
44
+ option_args.concat("#{key}: '#{value}', ")
45
+ end
46
+ end
47
+ args = required_args.concat(option_args, '**')
48
+ end
49
+ insert_into_file "lib/legion/extensions/#{lex}/runners/#{name}.rb", after: "extend Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined? 'Helpers::Lex'\n" do
50
+ "
51
+ def #{function}(#{args})
52
+ { success: true }
53
+ end\n"
54
+ end
55
+
56
+ insert_into_file("spec/runners/#{name}_spec.rb", after: "it { should be_a Module }\n") do
57
+ result = " it { is_expected.to respond_to(:#{function}).with_any_keywords }\n"
58
+ if @arg_keys.count.positive?
59
+ result.concat " it { is_expected.to respond_to(:#{function}).with_keywords(:#{@arg_keys.join(', :')}) }\n"
60
+ end
61
+ result
62
+ end
63
+
64
+ insert_into_file("spec/runners/#{name}_spec.rb", before: " end\n") do
65
+ " it('#{function} returns a success') { expect(test_class.#{function}[:success]).to eq true }\n"
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,6 @@
1
+ module Legion::Extensions::<%= config[:lex].capitalize %>
2
+ module Actor
3
+ class <%= config[:name].capitalize %> < Legion::Extensions::Actors::<%= config[:type].capitalize %>
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,69 @@
1
+ image: ruby:2.7
2
+
3
+ pipelines:
4
+ tags:
5
+ "v*":
6
+ - step:
7
+ name: Rubocop
8
+ caches:
9
+ - bundler
10
+ script:
11
+ - gem install rubocop
12
+ - gem update rubocop
13
+ - rubocop
14
+ - step:
15
+ name: RSpec
16
+ caches:
17
+ - bundler
18
+ script:
19
+ - gem install bundler
20
+ - gem update bundler
21
+ - bundle update
22
+ - bundle exec rspec
23
+ - step:
24
+ name: Push to RubyGems
25
+ deployment: RubyGems
26
+ script:
27
+ - gem install bundler gem-release rspec
28
+ - bundle install
29
+ - (umask 077 ; echo $gem_creds | base64 --decode > ~/.gem/credentials)
30
+ - gem release
31
+ artifacts:
32
+ - pkg/**
33
+ branches:
34
+ master:
35
+ - step:
36
+ caches:
37
+ - bundler
38
+ script:
39
+ - gem install rubocop
40
+ - gem update rubocop
41
+ - rubocop
42
+ - step:
43
+ caches:
44
+ - bundler
45
+ script:
46
+ - gem install bundler
47
+ - gem update bundler
48
+ - bundle update
49
+ - bundle exec rspec
50
+ develop:
51
+ - step:
52
+ caches:
53
+ - bundler
54
+ script:
55
+ - gem install rubocop
56
+ - gem update rubocop
57
+ - rubocop
58
+ - step:
59
+ caches:
60
+ - bundler
61
+ script:
62
+ - gem install bundler
63
+ - gem update bundler
64
+ - bundle update
65
+ - bundle exec rspec
66
+
67
+ definitions:
68
+ caches:
69
+ bundler: /usr/local/bundle
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/legion/extensions/<%= config[:lex] %>/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'lex-<%= config[:lex] %>'
5
+ spec.version = Legion::Extensions::<%= config[:class_name] %>::VERSION
6
+ spec.authors = ['Esity']
7
+ spec.email = ['matthewdiverson@gmail.com']
8
+
9
+ spec.summary = 'LEX::<%= config[:class_name] %>'
10
+ spec.description = 'Connects Legion to <%= config[:class_name] %>'
11
+ spec.homepage = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>/src'
17
+ spec.metadata['documentation_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/'
18
+ spec.metadata['changelog_uri'] = 'https://legionio.atlassian.net/wiki/spaces/LEX/pages/'
19
+ spec.metadata['bug_tracker_uri'] = 'https://bitbucket.org/legion-io/lex-<%= config[:lex] %>/issues'
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rubocop'
25
+ spec.add_development_dependency 'simplecov'
26
+ end
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,9 @@
1
+ require 'legion/extensions/<%= config[:lex] %>/version'
2
+
3
+ module Legion
4
+ module Extensions
5
+ module <%= config[:class_name] %>
6
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ RSpec.describe Legion::Extensions::<%= config[:class_name] %> do
2
+ it 'has a version number' do
3
+ expect(Legion::Extensions::<%= config[:class_name] %>::VERSION).not_to be nil
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Esity
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,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,2 @@
1
+ # Legion::Extensions::<%= config[:class_name] %>
2
+ Another Legion Extension
@@ -0,0 +1,15 @@
1
+ Metrics/LineLength:
2
+ Max: 120
3
+ Metrics/MethodLength:
4
+ Max: 30
5
+ Metrics/ClassLength:
6
+ Max: 1500
7
+ Style/Documentation:
8
+ Enabled: false
9
+ AllCops:
10
+ TargetRubyVersion: 2.5
11
+ NewCops: enable
12
+ Style/FrozenStringLiteralComment:
13
+ Enabled: false
14
+ Naming/FileName:
15
+ Enabled: false
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ require 'legion/extensions/<%= config[:lex] %>'
3
+
4
+ RSpec.configure do |config|
5
+ config.example_status_persistence_file_path = '.rspec_status'
6
+ config.disable_monkey_patching!
7
+
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Legion
2
+ module Extensions
3
+ module <%= config[:class_name] %>
4
+ VERSION = '0.1.1'.freeze
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Legion::Extensions::<%= @lex.capitalize %>>
2
+ module Transport
3
+ module Exchanges
4
+ class <%= @name.capitalize %> < Legion::Transport::Exchange
5
+ def exchange_name
6
+ '<%= @name %>'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module Legion::Extensions::<%= @lex.capitalize %>
2
+ module Transport
3
+ module Messages
4
+ class Conditioner < Legion::Transport::Message
5
+ def initialize(payload, status, options = {})
6
+ @payload = payload
7
+ @options = options
8
+ @status = status
9
+ @routing_key = routing_key
10
+ validate
11
+ end
12
+
13
+ def routing_key
14
+ "<%= @lex %>.<%= @name %>"
15
+ end
16
+
17
+ #def exchange
18
+ # Legion::Extensions::Conditioner::Transport::Exchanges::Conditioner
19
+ #end
20
+
21
+ def message(payload = @payload, _options = {})
22
+ Legion::JSON.dump(payload)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ module Legion::Extensions::<%= @lex.capitalize %>
2
+ module Transport
3
+ module Queues
4
+ class <%= @name.capitalize %> < Legion::Transport::Queue
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Legion
2
+ module Extensions
3
+ module <%= config[:lex].capitalize %>
4
+ module Runners
5
+ module <%= config[:name].capitalize %>
6
+ extend Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined? 'Helpers::Lex'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'legion/extensions/<%= config[:lex] %>/runners/<%= config[:name] %>'
3
+
4
+ RSpec.describe Legion::Extensions::<%= config[:lex].capitalize %>::Runners::<%= config[:name].capitalize %> do
5
+ it { should be_a Module }
6
+ Legion::Extensions::<%= config[:lex].capitalize %>::Runners::<%= config[:name].capitalize %>.extend Legion::Extensions::<%= config[:lex].capitalize %>::Runners::<%= config[:name].capitalize %>
7
+
8
+ describe 'Functions should work with arguments' do
9
+ let(:test_class) { Class.new { extend Legion::Extensions::<%= config[:lex].capitalize %>::Runners::<%= config[:name].capitalize %> } }
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ module Legion
2
+ class Cli
3
+ class Relationship < Thor
4
+ desc 'create', 'creates a new relationship'
5
+ def create(_name, _type)
6
+ trigger_id = invoke('legion:cli:function:find', [], internal: true, capture: true)
7
+ end
8
+
9
+ desc 'activate', 'actives a relationship'
10
+ def active; end
11
+
12
+ desc 'deactivate', 'deactivates a relationship'
13
+ def deactivate; end
14
+
15
+ desc 'modify', 'modify an existing relationship'
16
+ def modify; end
17
+
18
+ desc 'delete', 'deletes a relationship'
19
+ def delete; end
20
+ end
21
+ end
22
+ end