Skip to content

Commit

Permalink
Rename command -> domain
Browse files Browse the repository at this point in the history
  • Loading branch information
azimux committed Mar 4, 2024
1 parent cdb3903 commit 8827dfa
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 77 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
env:
cache-name: cache-foobara
with:
path: ~/work/command-generator/foobara
path: ~/work/domain-generator/foobara
key: ${{ env.cache-name }}-${{ env.foobara_branch }}-${{ env.foobara_sha1 }}
restore-keys: |
${{ env.cache-name }}-${{ env.foobara_branch }}-
Expand Down Expand Up @@ -67,9 +67,9 @@ jobs:
run: |
set -e
mkdir -p .bundle
echo -e "---\nBUNDLE_LOCAL__FOOBARA: '/home/runner/work/command-generator/foobara'" > .bundle/config
echo -e "---\nBUNDLE_LOCAL__FOOBARA: '/home/runner/work/domain-generator/foobara'" > .bundle/config
mkdir ../../foobara
ln -s ../../command-generator/foobara ../../foobara/foobara
ln -s ../../domain-generator/foobara ../../foobara/foobara
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GIT
PATH
remote: .
specs:
foobara-command-generator (0.0.1)
foobara-domain-generator (0.0.1)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -144,7 +144,7 @@ PLATFORMS

DEPENDENCIES
foobara!
foobara-command-generator!
foobara-domain-generator!
foobara-files-generator!
foobara-rubocop-rules!
foobara-spec-helpers!
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Foobara::CommandGenerator
# Foobara::DomainGenerator

TODO: Delete this and the text below, and describe your gem

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/foobara/command_generator`. To experiment with that code,
into a gem. Put your Ruby code in the file `lib/foobara/domain_generator`. To experiment with that code,
run `bin/console` for an interactive prompt.

## Installation
Expand Down Expand Up @@ -43,7 +43,7 @@ push git commits and the created tag, and push the `.gem` file to [rubygems.org]
## Contributing

Bug reports and pull requests are welcome on GitHub
at https://github.com/[USERNAME]/foobara-command-generator.
at https://github.com/[USERNAME]/foobara-domain-generator.

## License

Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "foobara/command_generator"
require "foobara/domain_generator"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
Expand Down
8 changes: 4 additions & 4 deletions foobara-domain-generator.gemspec
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require_relative "src/version"

Gem::Specification.new do |spec|
spec.name = "foobara-command-generator"
spec.version = Foobara::Generators::CommandGenerator::VERSION
spec.name = "foobara-domain-generator"
spec.version = Foobara::Generators::DomainGenerator::VERSION
spec.authors = ["Miles Georgi"]
spec.email = ["azimux@gmail.com"]

spec.summary = "Generates Foobara commands"
spec.homepage = "https://github.com/foobara/generators-command-generator"
spec.summary = "Generates Foobara domains"
spec.homepage = "https://github.com/foobara/generators-domain-generator"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.2.2"

Expand Down
34 changes: 17 additions & 17 deletions spec/foobara/generators/generate_domain_spec.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
RSpec.describe Foobara::Generators::CommandGenerator::GenerateCommand do
let(:command_name) { "SomeOrg::SomeDomain::SomeCommand" }
RSpec.describe Foobara::Generators::DomainGenerator::GenerateDomain do
let(:domain_name) { "SomeOrg::SomeDomain::SomeDomain" }

let(:inputs) do
{
command_name:,
domain_name:,
description: "whatever"
}
end
let(:command) { described_class.new(inputs) }
let(:outcome) { command.run }
let(:domain) { described_class.new(inputs) }
let(:outcome) { domain.run }
let(:result) { outcome.result }

it "generates a command" do
it "generates a domain" do
expect(outcome).to be_success

command_file = result["src/some_org/some_domain/some_command.rb"]
expect(command_file).to include("module SomeOrg")
expect(command_file).to include("module SomeDomain")
expect(command_file).to include("class SomeCommand")
domain_file = result["src/some_org/some_domain/some_domain.rb"]
expect(domain_file).to include("module SomeOrg")
expect(domain_file).to include("module SomeDomain")
expect(domain_file).to include("class SomeDomain")
end

context "with all options" do
let(:inputs) do
{
command_name: "SomeCommand",
domain_name: "SomeDomain",
description: "whatever",
organization_name: "SomeOrg",
domain_name: "SomeDomain",
full_module_name: "SomeOrg::SomeDomain::SomeCommand"
full_module_name: "SomeOrg::SomeDomain::SomeDomain"
}
end

it "generates a command using the given options" do
it "generates a domain using the given options" do
expect(outcome).to be_success

command_file = result["src/some_org/some_domain/some_command.rb"]
expect(command_file).to include("module SomeOrg")
expect(command_file).to include("module SomeDomain")
expect(command_file).to include("class SomeCommand")
domain_file = result["src/some_org/some_domain/some_domain.rb"]
expect(domain_file).to include("module SomeOrg")
expect(domain_file).to include("module SomeDomain")
expect(domain_file).to include("class SomeDomain")
end
end
end
24 changes: 12 additions & 12 deletions spec/foobara/generators/write_domain_to_disk_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
RSpec.describe Foobara::Generators::CommandGenerator::WriteCommandToDisk do
let(:command) { described_class.new(inputs) }
let(:outcome) { command.run }
RSpec.describe Foobara::Generators::DomainGenerator::WriteDomainToDisk do
let(:domain) { described_class.new(inputs) }
let(:outcome) { domain.run }
let(:result) { outcome.result }
let(:errors) { outcome.errors }
let(:inputs) do
{
command_config:,
domain_config:,
output_directory:
}
end
let(:command_config) do
let(:domain_config) do
{
command_name:,
domain_name:,
description: "whatever"
}
end
let(:command_name) { "SomeOrg::SomeDomain::SomeCommand" }
let(:output_directory) { "#{__dir__}/../../../tmp/command_test_suite_output" }
let(:domain_name) { "SomeOrg::SomeDomain::SomeDomain" }
let(:output_directory) { "#{__dir__}/../../../tmp/domain_test_suite_output" }

before do
# rubocop:disable RSpec/AnyInstance
Expand All @@ -30,21 +30,21 @@
it "contains base files" do
expect(outcome).to be_success

expect(command.paths_to_source_code.keys).to include("src/some_org/some_domain/some_command.rb")
expect(domain.paths_to_source_code.keys).to include("src/some_org/some_domain/some_domain.rb")
end
end

describe "#output_directory" do
context "with no output directory" do
let(:inputs) do
{
command_config:
domain_config:
}
end

it "writes files to the current directory" do
command.cast_and_validate_inputs
expect(command.output_directory).to eq(".")
domain.cast_and_validate_inputs
expect(domain.output_directory).to eq(".")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
end

require "foobara/spec_helpers/all"
require "foobara/command_generator"
require "foobara/domain_generator"
14 changes: 7 additions & 7 deletions src/domain_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

module Foobara
module Generators
module CommandGenerator
class CommandConfig < Foobara::Model
module DomainGenerator
class DomainConfig < Foobara::Model
attributes do
command_name :string, :required
domain_name :string, :required
description :string, :allow_nil
organization_name :string, :allow_nil
domain_name :string, :allow_nil
Expand All @@ -17,16 +17,16 @@ class CommandConfig < Foobara::Model
def initialize(attributes = nil, options = {})
full_module_name = attributes[:full_module_name]
module_path = full_module_name&.split("::")
command_name = attributes[:command_name]
domain_name = attributes[:domain_name]
description = attributes[:description]
organization_name = attributes[:organization_name]
domain_name = attributes[:domain_name]

if organization_name.nil? && domain_name.nil? && full_module_name.nil?
full_module_name = command_name
full_module_name = domain_name
module_path = full_module_name.split("::")

*prefix, command_name = module_path
*prefix, domain_name = module_path

*organization_parts, domain_name = prefix

Expand All @@ -37,7 +37,7 @@ def initialize(attributes = nil, options = {})

super(
{
command_name:,
domain_name:,
description:,
organization_name:,
domain_name:,
Expand Down
16 changes: 8 additions & 8 deletions src/domain_generator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module Foobara
module Generators
module CommandGenerator
module DomainGenerator
module Generators
class CommandGenerator < Foobara::FilesGenerator
class DomainGenerator < Foobara::FilesGenerator
class << self
def manifest_to_generator_classes(manifest)
case manifest
when CommandConfig
when DomainConfig
[
Generators::CommandGenerator
Generators::DomainGenerator
]
else
# :nocov:
Expand All @@ -19,7 +19,7 @@ def manifest_to_generator_classes(manifest)
end

def template_path
["src", "command.rb.erb"]
["src", "domain.rb.erb"]
end

def target_path
Expand All @@ -30,7 +30,7 @@ def target_path
["src", *path, file]
end

alias command_config relevant_manifest
alias domain_config relevant_manifest

def templates_dir
"#{__dir__}/../templates"
Expand All @@ -39,12 +39,12 @@ def templates_dir
# TODO: promote this up to base project
def ==(other)
# :nocov:
self.class == other.class && command_config == other.command_config
self.class == other.class && domain_config == other.domain_config
# :nocov:
end

def hash
command_config.hash
domain_config.hash
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions src/generate_domain.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require "pathname"

require_relative "command_config"
require_relative "domain_config"

module Foobara
module Generators
module CommandGenerator
class GenerateCommand < Foobara::Generators::Generate
module DomainGenerator
class GenerateDomain < Foobara::Generators::Generate
class MissingManifestError < RuntimeError; end

possible_error MissingManifestError

inputs CommandConfig
inputs DomainConfig

def execute
add_initial_elements_to_generate
Expand All @@ -25,7 +25,7 @@ def execute
attr_accessor :manifest_data

def base_generator
Generators::CommandGenerator
Generators::DomainGenerator
end

# TODO: delegate this to base_generator
Expand All @@ -37,11 +37,11 @@ def templates_dir
end

def add_initial_elements_to_generate
elements_to_generate << command_config
elements_to_generate << domain_config
end

def command_config
@command_config ||= CommandConfig.new(inputs)
def domain_config
@domain_config ||= DomainConfig.new(inputs)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Foobara
module Generators
module CommandGenerator
module DomainGenerator
VERSION = "0.0.1".freeze
end
end
Expand Down
16 changes: 8 additions & 8 deletions src/write_domain_to_disk.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require_relative "generate_command"
require_relative "generate_domain"

module Foobara
module Generators
module CommandGenerator
class WriteCommandToDisk < Foobara::Generators::WriteGeneratedFilesToDisk
module DomainGenerator
class WriteDomainToDisk < Foobara::Generators::WriteGeneratedFilesToDisk
class << self
def generator_key
"command"
"domain"
end
end

depends_on GenerateCommand
depends_on GenerateDomain

inputs do
command_config CommandConfig, :required
domain_config DomainConfig, :required
# TODO: should be able to delete this and inherit it
output_directory :string
end
Expand All @@ -37,8 +37,8 @@ def default_output_directory
end

def generate_file_contents
# TODO: just pass this in as the inputs instead of the command??
self.paths_to_source_code = run_subcommand!(GenerateCommand, command_config.attributes)
# TODO: just pass this in as the inputs instead of the domain??
self.paths_to_source_code = run_subdomain!(GenerateDomain, domain_config.attributes)
end

def run_post_generation_tasks
Expand Down
Loading

0 comments on commit 8827dfa

Please sign in to comment.