adjective-rpg 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +5 -0
- data/README.md +33 -0
- data/Rakefile +66 -0
- data/Thorfile +7 -0
- data/adjective-rpg.gemspec +53 -0
- data/lib/.DS_Store +0 -0
- data/lib/adjective.rb +63 -0
- data/lib/generators/setup_generator.rb +14 -0
- data/lib/included_models.rb +15 -0
- data/lib/modules/imbibable.rb +41 -0
- data/lib/modules/vulnerable.rb +65 -0
- data/lib/railties.rb +12 -0
- data/lib/tasks/migrate.thor +105 -0
- data/lib/tasks/migrate_adjective.rake +43 -0
- data/lib/templates/add_columns_migration.rb +65 -0
- data/lib/templates/all_tables.rb +9 -0
- data/lib/templates/create_adjective_class.rb +49 -0
- data/lib/templates/create_table_migration.rb +61 -0
- data/lib/templates/static/Thorfile +7 -0
- data/lib/templates/static/adjective.rb +4 -0
- data/lib/utils/string_patches.rb +23 -0
- data/lib/version.rb +5 -0
- data/sig/adjective/rpg.rbs +6 -0
- metadata +226 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d23d1564000544031c02aa133ff7c70e84d19de797006f12d5f3b8c8bb9b4a6e
|
4
|
+
data.tar.gz: 578435313a63965b6e6db15247cce9d54cc0d93ec8650925cbdf8a35856ea7f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75839d47ad7c1ebffcc52f0b374fd3ceb32be9bcecb9f25139daa38aff5fbb0ff470b7d9a7b2153799f55b18441a0bb1a461fe83811b836d054cfe04a76ebdc6
|
7
|
+
data.tar.gz: a15af2cb9239ca9539309e791bbf4f72e226afba5c856f8ec1b3d9facd4c4dbf6ad6eb4c63a894357dd521d77a98bdd804c10daefd4a568767e614b3c21c3b4b
|
data/.DS_Store
ADDED
Binary file
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Adjective
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
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/adjective/rpg`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
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.
|
26
|
+
|
27
|
+
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).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/adjective-rpg.
|
32
|
+
|
33
|
+
## Integration Planning
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
require 'fileutils'
|
6
|
+
Dir.glob('lib/tasks/**/*.rake').each { |r| load r }
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
task default: :spec
|
11
|
+
Rake::Task.define_task('adjective:db:generate_all_tables')
|
12
|
+
|
13
|
+
namespace :spec do
|
14
|
+
task :plain do
|
15
|
+
system("rspec spec/adjective/plain_specs/** --require ./spec/adjective/plain_helper")
|
16
|
+
end
|
17
|
+
|
18
|
+
task :rails do
|
19
|
+
system("rspec spec/adjective/rails_specs/** --require ./spec/adjective/rails_helper")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
namespace :build do
|
24
|
+
task :gem do
|
25
|
+
system("gem build adjective-rpg.gemspec")
|
26
|
+
# system("gem install adjective-0.1.0.gem")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
namespace :adjective do
|
31
|
+
task :install do
|
32
|
+
# plain_dummy install command:
|
33
|
+
# rake adjective:install -- config_path=spec/plain_dummy/ thorfile_path=spec/plain_dummy/
|
34
|
+
|
35
|
+
# dummy install command:
|
36
|
+
# rake adjective:install -- config_path=spec/dummy/config/initializers thorfile_path=spec/dummy/
|
37
|
+
|
38
|
+
config_install_path = ARGV.find { |arg| arg.include?("config_path=") }&.split("=")&.last || "config/initializers"
|
39
|
+
thorfile_install_path = ARGV.find { |arg| arg.include?("thorfile_path=") }&.split("=")&.last || Dir.pwd
|
40
|
+
|
41
|
+
loaded_feature = $LOADED_FEATURES.find { |feature| feature.include?('adjective') }
|
42
|
+
adj_thorfile_location = File.join(File.dirname(loaded_feature), 'templates/static/Thorfile')
|
43
|
+
adj_config_location = File.join(File.dirname(loaded_feature), 'templates/static/adjective.rb')
|
44
|
+
|
45
|
+
begin
|
46
|
+
if !File.directory?(thorfile_install_path)
|
47
|
+
raise Errno::ENOENT, "Thorfile install dir not found: #{thorfile_install_path}. Please ensure that this directory exists."
|
48
|
+
end
|
49
|
+
FileUtils.cp(adj_thorfile_location, thorfile_install_path)
|
50
|
+
puts "\e[32mInstalled the Adjective Thorfile to: #{File.join(thorfile_install_path, "Thorfile")}\e[0m"
|
51
|
+
rescue => e
|
52
|
+
puts "\e[31mError occured while copying the Adjective Thorfile: #{e.message}\e[0m"
|
53
|
+
end
|
54
|
+
|
55
|
+
begin
|
56
|
+
if !File.directory?(config_install_path)
|
57
|
+
raise Errno::ENOENT, "Adjective config install dir not found: #{config_install_path}. Please ensure that this directory exists."
|
58
|
+
end
|
59
|
+
FileUtils.cp(adj_config_location, config_install_path)
|
60
|
+
puts "\e[32mInstalled the Adjective configs to: #{File.join(config_install_path, "adjective.rb")}\e[0m"
|
61
|
+
rescue => e
|
62
|
+
puts "\e[31mError occured while copying the Adjective Thorfile: #{e.message}\e[0m"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/Thorfile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "adjective-rpg"
|
7
|
+
spec.version = Adjective::VERSION
|
8
|
+
spec.authors = ["Kevin Maze"]
|
9
|
+
spec.email = ["rhoxiodbc@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A gem to help you get RPG games built quickly in Ruby environments"
|
12
|
+
spec.description = "Incomplete and in early stages."
|
13
|
+
spec.homepage = "https://www.google.com"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/Rhoxio/adjective-rpg"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/Rhoxio/adjective-rpg/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
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", "tasks/**/*.rake", "tasks/**/*.thor"]
|
33
|
+
|
34
|
+
# Uncomment to register a new dependency of your gem
|
35
|
+
|
36
|
+
# Gem Dependencies
|
37
|
+
spec.add_dependency "rake"
|
38
|
+
spec.add_dependency "thor"
|
39
|
+
|
40
|
+
# Dev Dependencies
|
41
|
+
spec.add_development_dependency "activerecord"
|
42
|
+
spec.add_development_dependency "pg"
|
43
|
+
spec.add_development_dependency "dotenv"
|
44
|
+
spec.add_development_dependency "rspec"
|
45
|
+
spec.add_development_dependency 'simplecov'
|
46
|
+
spec.add_development_dependency 'awesome_print'
|
47
|
+
spec.add_development_dependency "database_cleaner"
|
48
|
+
spec.add_development_dependency "rails", "~> 7.0.6"
|
49
|
+
spec.add_development_dependency "tzinfo-data"
|
50
|
+
|
51
|
+
# For more information and examples about making a new gem, check out our
|
52
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
53
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/adjective.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "version"
|
4
|
+
require "active_record"
|
5
|
+
require 'thor'
|
6
|
+
require 'awesome_print'
|
7
|
+
|
8
|
+
require_relative "modules/vulnerable"
|
9
|
+
require_relative "modules/imbibable"
|
10
|
+
require_relative "utils/string_patches"
|
11
|
+
require_relative "templates/add_columns_migration"
|
12
|
+
require_relative "templates/create_table_migration"
|
13
|
+
require_relative "templates/create_adjective_class"
|
14
|
+
|
15
|
+
module Adjective
|
16
|
+
|
17
|
+
if defined?(Rails)
|
18
|
+
require 'railties'
|
19
|
+
require_relative "railties"
|
20
|
+
require_relative "generators/setup_generator"
|
21
|
+
# ActiveSupport.on_load(:active_record) do
|
22
|
+
# extend Adjective::Models
|
23
|
+
# end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Error < StandardError; end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
attr_accessor :configuration
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configure
|
33
|
+
self.configuration ||= Configuration.new
|
34
|
+
yield(configuration) if block_given?
|
35
|
+
end
|
36
|
+
|
37
|
+
class Configuration
|
38
|
+
attr_accessor :use_active_record, :config_file_path, :root, :migration_path, :models_path, :use_rails
|
39
|
+
|
40
|
+
def initialize
|
41
|
+
@use_active_record = true
|
42
|
+
@use_rails = defined?(Rails) ? true : false
|
43
|
+
# Need to set this up to ensure that if AR is off, it doesn't auto-set shit.
|
44
|
+
|
45
|
+
@root = use_rails ? Rails.root : "."
|
46
|
+
|
47
|
+
@config_file_path = "#{root}/config/initializers/adjective.rb"
|
48
|
+
@migration_path = "#{root}/db/migrate"
|
49
|
+
@models_path = "#{root}/app/models"
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_new_root(root_path)
|
53
|
+
@root = root_path
|
54
|
+
@config_file_path = "#{root_path}/config/initializers/adjective.rb"
|
55
|
+
@migration_path = "#{root_path}/db/migrate"
|
56
|
+
@models_path = "#{root_path}/app/models"
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Adjective
|
4
|
+
module Generators
|
5
|
+
class SetupGenerator < Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __dir__)
|
7
|
+
desc 'Creates an Adjective config file.'
|
8
|
+
|
9
|
+
def copy_config
|
10
|
+
template 'adjective.rb', "#{Rails.root}/config/initializers/adjective.rb"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Adjective
|
2
|
+
class IncludedModels
|
3
|
+
def initialize
|
4
|
+
@models = nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def find_included_models
|
8
|
+
Dir[Rails.root.join('app', 'models', '**', '*.rb')].each do |file|
|
9
|
+
require_dependency file
|
10
|
+
end
|
11
|
+
# model_path = Adjective.configuration.models_path
|
12
|
+
ap ApplicationRecord.descendants
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Module for experience gain
|
2
|
+
module Adjective
|
3
|
+
module Imbibable
|
4
|
+
def init_imbibable(args = {}, &block)
|
5
|
+
if !Adjective.configuration.use_active_record
|
6
|
+
define_imbibable_instance_variables(imbibable_default_data)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def imbibable_default_data
|
11
|
+
{
|
12
|
+
experience: 0,
|
13
|
+
level: 1
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def define_imbibable_instance_variables(args)
|
18
|
+
args.each do |key, value|
|
19
|
+
self.class.send(:attr_accessor, key)
|
20
|
+
self.instance_variable_set("@#{key.to_s}", value)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.adjective_columns
|
25
|
+
<<-RUBY
|
26
|
+
# Vulnerable Attributes
|
27
|
+
t.integer :total_experience
|
28
|
+
t.integer :level
|
29
|
+
RUBY
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.adjective_add_columns(klass)
|
33
|
+
columns = <<-RUBY
|
34
|
+
# Imbibable Attributes
|
35
|
+
add_column {{klass}}, :total_experience, :integer
|
36
|
+
add_column {{klass}}, :level, :integer
|
37
|
+
RUBY
|
38
|
+
columns.gsub("{{klass}}", ":#{klass.downcase}")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Adjective
|
2
|
+
module Vulnerable
|
3
|
+
|
4
|
+
VULNERABLE_ATTRIBUTES = [:hitpoints, :max_hitpoints]
|
5
|
+
|
6
|
+
# TODO:
|
7
|
+
|
8
|
+
# dont validate attrs - select valid ones, makes it more flexible. can pass
|
9
|
+
# full attr objects through this way when setting up a model.
|
10
|
+
|
11
|
+
# write the other logic
|
12
|
+
|
13
|
+
def init_vulnerable(args = {}, &block)
|
14
|
+
if !Adjective.configuration.use_active_record
|
15
|
+
define_vulnerable_instance_variables(vulnerable_default_data)
|
16
|
+
end
|
17
|
+
yield(self) if block_given?
|
18
|
+
# validate_vulnerable_attributes(args)
|
19
|
+
end
|
20
|
+
|
21
|
+
def vulnerable_default_data
|
22
|
+
{
|
23
|
+
hitpoints: 1,
|
24
|
+
max_hitpoints: 10
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def set_vulnerable_data(args)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def define_vulnerable_instance_variables(args)
|
33
|
+
args.each do |key, value|
|
34
|
+
self.class.send(:attr_accessor, key)
|
35
|
+
self.instance_variable_set("@#{key.to_s}", value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.adjective_columns
|
40
|
+
<<-RUBY
|
41
|
+
# Vulnerable Attributes
|
42
|
+
t.integer :hitpoints
|
43
|
+
t.integer :max_hitpoints
|
44
|
+
RUBY
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.adjective_add_columns(klass)
|
48
|
+
columns = <<-RUBY
|
49
|
+
# Vulnerable Attributes
|
50
|
+
add_column {{klass}}, :hitpoints, :integer
|
51
|
+
add_column {{klass}}, :max_hitpoints, :integer
|
52
|
+
RUBY
|
53
|
+
columns.gsub("{{klass}}", ":#{klass.downcase}")
|
54
|
+
end
|
55
|
+
|
56
|
+
# private
|
57
|
+
|
58
|
+
# def validate_vulnerable_attributes(args)
|
59
|
+
# if !args.keys.all? {|key| VALID_VULNERABLE_ATTRIBUTES.include?(key)}
|
60
|
+
# raise ArgumentError, "Provided invalid key as default attribute. Gave keys: #{args.keys}; valid keys are: #{VALID_VULNERABLE_ATTRIBUTES}"
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/lib/railties.rb
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
# These are assumed to be run from the project root dir.
|
4
|
+
|
5
|
+
# Plain Generators for the Test Setup
|
6
|
+
# thor adjective:generate:columns_for Character --includes Vulnerable --config spec/plain_dummy/adjective
|
7
|
+
# thor adjective:generate:scaffold_for Enemy --includes Vulnerable --config spec/plain_dummy/adjective
|
8
|
+
|
9
|
+
# Rails Generators for Test Setup
|
10
|
+
# thor adjective:generate:scaffold_for Enemy --includes Vulnerable --config spec/dummy/config/initializers/adjective --rails_load_path ../../spec/dummy/config/environment
|
11
|
+
# thor adjective:generate:columns_for Enemy --includes Vulnerable --config spec/dummy/config/initializers/adjective --rails_load_path ../../spec/dummy/config/environment
|
12
|
+
|
13
|
+
# TODO:
|
14
|
+
# Need to set a deault path for adjective loading from a Rails project.
|
15
|
+
# Clean shit up. Lots of duplication here.
|
16
|
+
# Might need to change the app conventions around to consider Rails a default.
|
17
|
+
|
18
|
+
module Adjective
|
19
|
+
class AdjectiveTasks < Thor
|
20
|
+
include Thor::Actions
|
21
|
+
|
22
|
+
default_rails_load_path = './config/environment'
|
23
|
+
|
24
|
+
package_name "adjective"
|
25
|
+
namespace 'adjective:generate'
|
26
|
+
|
27
|
+
desc "columns_for", "generates the needed migration columns for the supplied model and included modules"
|
28
|
+
method_options :includes => :array
|
29
|
+
method_options :config => :string
|
30
|
+
method_options :rails_load_path => :string
|
31
|
+
def columns_for(model)
|
32
|
+
# This assumes that you are running the command from the root of your project when you pass in relative --config
|
33
|
+
# into the generator. I might need to make it so you can fully override it with an ENV variable, but the relative
|
34
|
+
# path works for the moment.
|
35
|
+
|
36
|
+
# The main issue is that the Adjective configs need to be required. I have to construct an absolute path
|
37
|
+
# in some sense because there's no guarantee that the defaults will always work.
|
38
|
+
# I think having them set them in the configs and once in the generation scripts or in an env var is
|
39
|
+
# perfectly reasonable. How else is the program supposed to know their custom file structure?
|
40
|
+
|
41
|
+
config_file_path = ENV['ADJECTIVE_CONFIG_PATH'] ||= options[:config]
|
42
|
+
adj_configs = File.join( Dir.pwd, config_file_path)
|
43
|
+
rails_load_path = options[:rails_load_path] ||= default_rails_load_path
|
44
|
+
|
45
|
+
require adj_configs
|
46
|
+
if Adjective.configuration.use_rails
|
47
|
+
require_relative rails_load_path
|
48
|
+
Adjective.configuration.set_new_root(Rails.root)
|
49
|
+
end
|
50
|
+
|
51
|
+
modules = !!options[:includes] ? options[:includes] : []
|
52
|
+
|
53
|
+
generator = Adjective::AddColumnsMigration.new(model, modules)
|
54
|
+
migration_class = generator.render
|
55
|
+
|
56
|
+
new_migration_path = File.join(Adjective.configuration.migration_path, generator.file_name)
|
57
|
+
|
58
|
+
File.open(new_migration_path, 'w') do |file|
|
59
|
+
file.write(migration_class)
|
60
|
+
end
|
61
|
+
say "Adjective migration created at: #{new_migration_path}", :green
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "scaffold_for", "generates a class definition and the relevant migrations based on Adjective configs"
|
66
|
+
method_options :includes => :array
|
67
|
+
method_options :config => :string
|
68
|
+
method_options :rails_load_path => :string
|
69
|
+
def scaffold_for(model)
|
70
|
+
config_file_path = ENV['ADJECTIVE_CONFIG_PATH'] ||= options[:config]
|
71
|
+
adj_configs = File.join( Dir.pwd, config_file_path)
|
72
|
+
rails_load_path = options[:rails_load_path] ||= default_rails_load_path
|
73
|
+
|
74
|
+
require adj_configs
|
75
|
+
|
76
|
+
if Adjective.configuration.use_rails
|
77
|
+
require_relative rails_load_path
|
78
|
+
Adjective.configuration.set_new_root(Rails.root)
|
79
|
+
end
|
80
|
+
|
81
|
+
modules = !!options[:includes] ? options[:includes] : []
|
82
|
+
|
83
|
+
generator = Adjective::CreateTableMigration.new(model, modules)
|
84
|
+
migration_class = generator.render
|
85
|
+
|
86
|
+
class_generator = Adjective::CreateAdjectiveClass.new(model, modules)
|
87
|
+
new_class_file = class_generator.render
|
88
|
+
|
89
|
+
new_migration_path = File.join(Adjective.configuration.migration_path, generator.file_name)
|
90
|
+
new_model_path = File.join(Adjective.configuration.models_path, class_generator.file_name)
|
91
|
+
|
92
|
+
File.open(new_migration_path, 'w') do |file|
|
93
|
+
file.write(migration_class)
|
94
|
+
say "Adjective migration created at: #{new_migration_path}", :green
|
95
|
+
end
|
96
|
+
|
97
|
+
File.open(new_model_path, 'w') do |file|
|
98
|
+
file.write(new_class_file)
|
99
|
+
say "New model created at: #{new_model_path}", :green
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'adjective'
|
2
|
+
|
3
|
+
namespace :adjective do
|
4
|
+
|
5
|
+
desc 'setup the initial config for Adjective'
|
6
|
+
task :setup do
|
7
|
+
Adjective::Generators::SetupGenerator.new.copy_config
|
8
|
+
end
|
9
|
+
|
10
|
+
task :test do
|
11
|
+
ap Adjective
|
12
|
+
path = ENV['ADJECTIVE_CONFIG_PATH']
|
13
|
+
ap path
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
namespace :db do
|
18
|
+
desc 'generate all migrations from Adjective based on default settings'
|
19
|
+
task :generate_all_tables do
|
20
|
+
path = ENV['ADJECTIVE_CONFIG_PATH'] ||= "config/adjective.yml"
|
21
|
+
|
22
|
+
# Load a copy of Adjective with the correct configs.
|
23
|
+
Adjective.configure do |config|
|
24
|
+
config.set_config_file_path(path)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
# template_migration_content = File.read('lib/templates/all_tables.rb')
|
30
|
+
# timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
31
|
+
|
32
|
+
# migration_name = "create_all_adjective_tables"
|
33
|
+
# new_migration_file_name = "#{timestamp}_#{migration_name}.rb"
|
34
|
+
# new_migration_path = File.join('db', 'migrate', new_migration_file_name)
|
35
|
+
|
36
|
+
# File.open(new_migration_path, 'w') do |file|
|
37
|
+
# file.write(template_migration_content)
|
38
|
+
# end
|
39
|
+
|
40
|
+
# puts "Created Adjective Migration at: #{new_migration_path}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Adjective
|
2
|
+
class AddColumnsMigration
|
3
|
+
attr_reader :module_classes, :modules, :class_name
|
4
|
+
|
5
|
+
def initialize(class_name, modules = [])
|
6
|
+
# raise ArgumentError, "Provided class_name of: #{class_name} was not a valid String." if (!!class_name || !class_name.is_a?(String))
|
7
|
+
@class_name = class_name
|
8
|
+
@modules = modules.map{|m| m&.downcase}
|
9
|
+
@version = "7.0"
|
10
|
+
@module_classes = given_modules
|
11
|
+
end
|
12
|
+
|
13
|
+
def migration_class
|
14
|
+
modules_string = @modules.map {|m| m.capitalize}.join("And")
|
15
|
+
"Add#{modules_string}To#{@class_name.camelize}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def file_name
|
19
|
+
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
20
|
+
migration_name = migration_class.underscore
|
21
|
+
return "#{timestamp}_#{migration_name}.rb"
|
22
|
+
end
|
23
|
+
|
24
|
+
def given_modules
|
25
|
+
@modules.map do |mod|
|
26
|
+
klass = "Adjective::#{mod.capitalize}".constantize
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def attribute_up_fields
|
31
|
+
@module_classes.map do |mod|
|
32
|
+
mod.adjective_add_columns(@class_name)
|
33
|
+
end.join("\n").chomp
|
34
|
+
end
|
35
|
+
|
36
|
+
def attribute_down_fields
|
37
|
+
attribute_up_fields.gsub("add_column", "remove_column")
|
38
|
+
end
|
39
|
+
|
40
|
+
def base_template
|
41
|
+
<<~TEMPLATE
|
42
|
+
class {{migration_class}} < ActiveRecord::Migration[{{version}}]
|
43
|
+
def up
|
44
|
+
{{add_methods}}
|
45
|
+
end
|
46
|
+
|
47
|
+
def down
|
48
|
+
{{remove_methods}}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
TEMPLATE
|
52
|
+
end
|
53
|
+
|
54
|
+
def render
|
55
|
+
base = base_template
|
56
|
+
base
|
57
|
+
.gsub("{{migration_class}}", migration_class.lstrip)
|
58
|
+
.gsub("{{add_methods}}", attribute_up_fields.lstrip)
|
59
|
+
.gsub("{{remove_methods}}", attribute_down_fields.lstrip)
|
60
|
+
.gsub("{{version}}", @version)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Adjective
|
2
|
+
class CreateAdjectiveClass
|
3
|
+
def initialize(class_name, modules = [])
|
4
|
+
@class_name = class_name
|
5
|
+
@modules = modules.map{|m| m&.downcase}
|
6
|
+
@module_classes = given_modules
|
7
|
+
end
|
8
|
+
|
9
|
+
def file_class_name
|
10
|
+
@class_name.capitalize
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_name
|
14
|
+
@class_name.downcase + ".rb"
|
15
|
+
end
|
16
|
+
|
17
|
+
def given_modules
|
18
|
+
@modules.map do |mod|
|
19
|
+
klass = "Adjective::#{mod.capitalize}".constantize
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def modules_string
|
24
|
+
@modules.map {|mod| " include Adjective::#{mod.capitalize}"}.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def inherited_classes
|
28
|
+
return "< ApplicationRecord" if Adjective.configuration.use_active_record
|
29
|
+
return ""
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_template
|
33
|
+
<<~TEMPLATE
|
34
|
+
class {{class_name}} {{active_record_inheritance}}
|
35
|
+
{{modules_string}}
|
36
|
+
end
|
37
|
+
TEMPLATE
|
38
|
+
end
|
39
|
+
|
40
|
+
def render
|
41
|
+
base = base_template
|
42
|
+
base
|
43
|
+
.gsub("{{class_name}}", file_class_name.lstrip)
|
44
|
+
.gsub("{{active_record_inheritance}}", inherited_classes.lstrip)
|
45
|
+
.gsub("{{modules_string}}", modules_string)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Adjective
|
2
|
+
class CreateTableMigration
|
3
|
+
attr_reader :module_classes, :modules, :class_name
|
4
|
+
|
5
|
+
def initialize(class_name, modules = [])
|
6
|
+
# raise ArgumentError, "Provided class_name of: #{class_name} was not a valid String." if (!!class_name || !class_name.is_a?(String))
|
7
|
+
@class_name = class_name
|
8
|
+
@modules = modules.map{|m| m&.downcase}
|
9
|
+
@version = "7.0"
|
10
|
+
@module_classes = given_modules
|
11
|
+
end
|
12
|
+
|
13
|
+
def class_name_sym
|
14
|
+
":#{@class_name.underscore.downcase}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def migration_class
|
18
|
+
modules_string = @modules.map {|m| m.capitalize}.join("And")
|
19
|
+
"Create#{@class_name.camelize}With#{modules_string}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_name
|
23
|
+
timestamp = Time.now.strftime('%Y%m%d%H%M%S')
|
24
|
+
migration_name = migration_class.underscore
|
25
|
+
return "#{timestamp}_#{migration_name}.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
def given_modules
|
29
|
+
@modules.map do |mod|
|
30
|
+
klass = "Adjective::#{mod.capitalize}".constantize
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def columns
|
35
|
+
@module_classes.map do |mod|
|
36
|
+
mod.adjective_columns
|
37
|
+
end.join("\n").chomp
|
38
|
+
end
|
39
|
+
|
40
|
+
def base_template
|
41
|
+
<<~TEMPLATE
|
42
|
+
class {{migration_class}} < ActiveRecord::Migration[{{version}}]
|
43
|
+
def change
|
44
|
+
create_table {{class_name}} do |t|
|
45
|
+
{{create_columns}}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
TEMPLATE
|
50
|
+
end
|
51
|
+
|
52
|
+
def render
|
53
|
+
base = base_template
|
54
|
+
base
|
55
|
+
.gsub("{{migration_class}}", migration_class.lstrip)
|
56
|
+
.gsub("{{class_name}}", class_name_sym.lstrip)
|
57
|
+
.gsub("{{create_columns}}", columns.lstrip)
|
58
|
+
.gsub("{{version}}", @version)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# This is primarily to ensure that consistent functionality is
|
2
|
+
# maintained and migration names and camelize works the same way it does in Rails.
|
3
|
+
# These were taken directly from the Rails repo.
|
4
|
+
|
5
|
+
class String
|
6
|
+
def underscore
|
7
|
+
self.gsub(/::/, '/').
|
8
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
9
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
10
|
+
tr("-", "_").
|
11
|
+
downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def camelize(uppercase_first_letter = true)
|
15
|
+
string = self
|
16
|
+
if uppercase_first_letter
|
17
|
+
string = string.sub(/^[a-z\d]*/) { |match| match.capitalize }
|
18
|
+
else
|
19
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
20
|
+
end
|
21
|
+
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
|
22
|
+
end
|
23
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: adjective-rpg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Maze
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pg
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: awesome_print
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: database_cleaner
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rails
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 7.0.6
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 7.0.6
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: tzinfo-data
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
description: Incomplete and in early stages.
|
168
|
+
email:
|
169
|
+
- rhoxiodbc@gmail.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".DS_Store"
|
175
|
+
- ".rspec"
|
176
|
+
- CHANGELOG.md
|
177
|
+
- README.md
|
178
|
+
- Rakefile
|
179
|
+
- Thorfile
|
180
|
+
- adjective-rpg.gemspec
|
181
|
+
- lib/.DS_Store
|
182
|
+
- lib/adjective.rb
|
183
|
+
- lib/generators/setup_generator.rb
|
184
|
+
- lib/included_models.rb
|
185
|
+
- lib/modules/imbibable.rb
|
186
|
+
- lib/modules/vulnerable.rb
|
187
|
+
- lib/railties.rb
|
188
|
+
- lib/tasks/migrate.thor
|
189
|
+
- lib/tasks/migrate_adjective.rake
|
190
|
+
- lib/templates/add_columns_migration.rb
|
191
|
+
- lib/templates/all_tables.rb
|
192
|
+
- lib/templates/create_adjective_class.rb
|
193
|
+
- lib/templates/create_table_migration.rb
|
194
|
+
- lib/templates/static/Thorfile
|
195
|
+
- lib/templates/static/adjective.rb
|
196
|
+
- lib/utils/string_patches.rb
|
197
|
+
- lib/version.rb
|
198
|
+
- sig/adjective/rpg.rbs
|
199
|
+
homepage: https://www.google.com
|
200
|
+
licenses: []
|
201
|
+
metadata:
|
202
|
+
homepage_uri: https://www.google.com
|
203
|
+
source_code_uri: https://github.com/Rhoxio/adjective-rpg
|
204
|
+
changelog_uri: https://github.com/Rhoxio/adjective-rpg/CHANGELOG.md
|
205
|
+
post_install_message:
|
206
|
+
rdoc_options: []
|
207
|
+
require_paths:
|
208
|
+
- lib
|
209
|
+
- tasks/**/*.rake
|
210
|
+
- tasks/**/*.thor
|
211
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 2.6.0
|
216
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - ">="
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
requirements: []
|
222
|
+
rubygems_version: 3.4.16
|
223
|
+
signing_key:
|
224
|
+
specification_version: 4
|
225
|
+
summary: A gem to help you get RPG games built quickly in Ruby environments
|
226
|
+
test_files: []
|