diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..620423d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,9 @@ +AllCops: + TargetRubyVersion: 2.6 + EnabledByDefault: true + +Style: + Enabled: false + +Layout: + Enabled: false \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..06889d0 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at waghanza@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [https://contributor-covenant.org/version/1/4][version] + +[homepage]: https://contributor-covenant.org +[version]: https://contributor-covenant.org/version/1/4/ diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..bde4798 --- /dev/null +++ b/Gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +source("https://rubygems.org") + +gemspec + +group :development, :test do + # Keep code consistency + gem "rubocop" +end diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..d9f5ac7 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2020 Marwan Rabbâa + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..ae882af --- /dev/null +++ b/Rakefile @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require('bundler/gem_tasks') +task(default: :spec) + +require('active_record') +require('active_record/database_configurations/database_config') +require('active_record/database_configurations/url_config') + +database_url = ENV.fetch('DATABASE_URL') + +namespace :db do + task :create do + database = ActiveRecord::DatabaseConfigurations::UrlConfig.new(nil, nil, database_url) + + ActiveRecord::Tasks::DatabaseTasks.create(database.config) + end + + task :migrate do + base_path = Gem.loaded_specs['benchmarker-data'].full_gem_path + full_path = File.join(base_path, 'db', 'migrations') + ActiveRecord::MigrationContext.new(full_path, ActiveRecord::SchemaMigration).migrate + end + + task :drop do + database = ActiveRecord::DatabaseConfigurations::UrlConfig.new(nil, nil, database_url) + + ActiveRecord::Tasks::DatabaseTasks.drop(database.config) + end +end diff --git a/benchmarker-data.gemspec b/benchmarker-data.gemspec new file mode 100644 index 0000000..c4db524 --- /dev/null +++ b/benchmarker-data.gemspec @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require_relative("lib/benchmarker/data/version") + +Gem::Specification.new do |spec| + spec.name = "benchmarker-data" + spec.version = Benchmarker::Data::VERSION + spec.authors = ["Marwan Rabbâa"] + spec.email = ["waghanza@gmail.com"] + + spec.summary = "Shared data for the benchmarker tools" + spec.homepage = "https://github.com/the-benchmarker/benchmarker-data" + spec.license = "MIT" + spec.required_ruby_version = "~> 2.6" + + spec.metadata["allowed_push_host"] = "https://rubygems.pkg.github.com" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["changelog_uri"] = "https://github.com/the-benchmarker/benchmarker-data/releases" + + spec.add_runtime_dependency("activerecord", "~> 6.0") + spec.add_runtime_dependency("pg", "~> 1.2") + spec.add_runtime_dependency("rake", "~> 13.0") + + spec.add_development_dependency("bundler", "~> 2.0") + + spec.files = Dir.glob("lib/**/*.rb") + spec.files << "LICENSE.txt" + spec.files << "Rakefile" + spec.require_paths = ["lib", "db/migrations"] +end diff --git a/benchmarker_data.gemspec b/benchmarker_data.gemspec deleted file mode 100644 index 1a2a216..0000000 --- a/benchmarker_data.gemspec +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -require_relative "lib/benchmarker/data/version" - -require "active_record" - -require "benchmarker/data/models/model" -require "benchmarker/data/models/language" -require "benchmarker/data/models/framework" -require "benchmarker/data/models/key" -require "benchmarker/data/models/metric" -require "benchmarker/data/models/concurrency" - -Gem::Specification.new do |spec| - spec.name = "benchmarker_data" - spec.version = Benchmarker::Data::VERSION - spec.summary = "Shared data for the benchmarker tools" - spec.description = "Shared data for the benchmarker tools" - spec.authors = "Marwan Rabbâa" - spec.email = "waghanza@gmail.com" - spec.homepage = "https://github.com/the-benchmarker/benchmarker-data" - spec.license = "MIT" - - spec.add_runtime_dependency "activerecord", "~> 6.0", ">= 6.0.2" - spec.add_runtime_dependency "rake", "~> 13.0", ">= 13.0.0" - - spec.files = `find *`.split("\n").uniq.sort.reject(&:empty?) - spec.require_paths = ["lib/benchmarker"] -end diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..8eb2257 --- /dev/null +++ b/bin/console @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require('bundler/setup') +require('benchmarker/data') + +require('irb') +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/lib/benchmarker/data/migrations/0001_languages.rb b/db/migrations/0001_languages.rb similarity index 75% rename from lib/benchmarker/data/migrations/0001_languages.rb rename to db/migrations/0001_languages.rb index 92360e1..2a2d0e5 100644 --- a/lib/benchmarker/data/migrations/0001_languages.rb +++ b/db/migrations/0001_languages.rb @@ -3,7 +3,7 @@ class Languages < ActiveRecord::Migration[6.0] def change create_table :languages do |t| - t.string :label, index: { unique: true } + t.string(:label, index: { unique: true }) end end end diff --git a/lib/benchmarker/data/migrations/0002_frameworks.rb b/db/migrations/0002_frameworks.rb similarity index 55% rename from lib/benchmarker/data/migrations/0002_frameworks.rb rename to db/migrations/0002_frameworks.rb index a888733..63a0d18 100644 --- a/lib/benchmarker/data/migrations/0002_frameworks.rb +++ b/db/migrations/0002_frameworks.rb @@ -3,10 +3,10 @@ class Frameworks < ActiveRecord::Migration[6.0] def change create_table :frameworks do |t| - t.string :label - t.references :language + t.string(:label) + t.references(:language) end - add_index :frameworks, [:label, :language_id], unique: true + add_index(:frameworks, %i[label language_id], unique: true) end end diff --git a/lib/benchmarker/data/migrations/0003_concurrencies.rb b/db/migrations/0003_concurrencies.rb similarity index 75% rename from lib/benchmarker/data/migrations/0003_concurrencies.rb rename to db/migrations/0003_concurrencies.rb index 74fa9f9..4946699 100644 --- a/lib/benchmarker/data/migrations/0003_concurrencies.rb +++ b/db/migrations/0003_concurrencies.rb @@ -3,7 +3,7 @@ class Concurrencies < ActiveRecord::Migration[6.0] def change create_table :concurrencies do |t| - t.numeric :level, index: { unique: true } + t.numeric(:level, index: { unique: true }) end end end diff --git a/lib/benchmarker/data/migrations/0004_keys.rb b/db/migrations/0004_keys.rb similarity index 73% rename from lib/benchmarker/data/migrations/0004_keys.rb rename to db/migrations/0004_keys.rb index 75019cf..dd772d1 100644 --- a/lib/benchmarker/data/migrations/0004_keys.rb +++ b/db/migrations/0004_keys.rb @@ -3,7 +3,7 @@ class Keys < ActiveRecord::Migration[6.0] def change create_table :keys do |t| - t.string :label, index: { unique: true } + t.string(:label, index: { unique: true }) end end end diff --git a/lib/benchmarker/data/migrations/0005_values.rb b/db/migrations/0005_values.rb similarity index 74% rename from lib/benchmarker/data/migrations/0005_values.rb rename to db/migrations/0005_values.rb index fd16eaf..18738ee 100644 --- a/lib/benchmarker/data/migrations/0005_values.rb +++ b/db/migrations/0005_values.rb @@ -3,8 +3,8 @@ class Values < ActiveRecord::Migration[6.0] def change create_table :values do |t| - t.float :value - t.references :key + t.float(:value) + t.references(:key) end end end diff --git a/db/migrations/0006_metrics.rb b/db/migrations/0006_metrics.rb new file mode 100644 index 0000000..f7d724c --- /dev/null +++ b/db/migrations/0006_metrics.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class Metrics < ActiveRecord::Migration[6.0] + def change + create_table :metrics do |t| + t.references(:framework) + t.references(:value) + t.references(:concurrency) + end + + add_index(:metrics, %i[framework_id value_id concurrency_id]) + end +end diff --git a/lib/benchmarker/data/migrations/0007_writable.rb b/db/migrations/0007_writable.rb similarity index 71% rename from lib/benchmarker/data/migrations/0007_writable.rb rename to db/migrations/0007_writable.rb index 5184158..ced4019 100644 --- a/lib/benchmarker/data/migrations/0007_writable.rb +++ b/db/migrations/0007_writable.rb @@ -3,8 +3,8 @@ class Writable < ActiveRecord::Migration[6.0] def change create_table :writable, id: false do |t| - t.references :language - t.references :framework + t.references(:language) + t.references(:framework) end end end diff --git a/lib/benchmarker/data.rb b/lib/benchmarker/data.rb new file mode 100644 index 0000000..c97e52b --- /dev/null +++ b/lib/benchmarker/data.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require("active_record") + +require("benchmarker/data/base") +require("benchmarker/data/language") +require("benchmarker/data/framework") +require("benchmarker/data/key") +require("benchmarker/data/metric") +require("benchmarker/data/concurrency") +require("benchmarker/data/value") diff --git a/lib/benchmarker/data/models/model.rb b/lib/benchmarker/data/base.rb similarity index 63% rename from lib/benchmarker/data/models/model.rb rename to lib/benchmarker/data/base.rb index bf17c10..05fb194 100644 --- a/lib/benchmarker/data/models/model.rb +++ b/lib/benchmarker/data/base.rb @@ -2,8 +2,9 @@ module Benchmarker module Data - class Model < ::ActiveRecord::Base + class Base < ::ActiveRecord::Base self.abstract_class = true + establish_connection end end end diff --git a/lib/benchmarker/data/models/concurrency.rb b/lib/benchmarker/data/concurrency.rb similarity index 72% rename from lib/benchmarker/data/models/concurrency.rb rename to lib/benchmarker/data/concurrency.rb index f1ac0f1..391197b 100644 --- a/lib/benchmarker/data/models/concurrency.rb +++ b/lib/benchmarker/data/concurrency.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + module Benchmarker module Data - class Concurrency < Model + class Concurrency < Base end end end diff --git a/lib/benchmarker/data/framework.rb b/lib/benchmarker/data/framework.rb new file mode 100644 index 0000000..bb596a6 --- /dev/null +++ b/lib/benchmarker/data/framework.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Benchmarker + module Data + class Framework < Base + belongs_to :language + end + end +end diff --git a/lib/benchmarker/data/models/framework.rb b/lib/benchmarker/data/key.rb similarity index 60% rename from lib/benchmarker/data/models/framework.rb rename to lib/benchmarker/data/key.rb index 252a46e..2adf932 100644 --- a/lib/benchmarker/data/models/framework.rb +++ b/lib/benchmarker/data/key.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true + module Benchmarker module Data - class Framework < Model - has_one :language + class Key < Base + belongs_to :metric end end end diff --git a/lib/benchmarker/data/models/key.rb b/lib/benchmarker/data/language.rb similarity index 75% rename from lib/benchmarker/data/models/key.rb rename to lib/benchmarker/data/language.rb index a635ca3..191f50e 100644 --- a/lib/benchmarker/data/models/key.rb +++ b/lib/benchmarker/data/language.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true + module Benchmarker module Data - class Key < Model + class Language < Base end end end diff --git a/lib/benchmarker/data/metric.rb b/lib/benchmarker/data/metric.rb new file mode 100644 index 0000000..de8104e --- /dev/null +++ b/lib/benchmarker/data/metric.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +module Benchmarker + module Data + class Metric < Base + belongs_to :framework + belongs_to :value + belongs_to :concurrency + end + end +end diff --git a/lib/benchmarker/data/migrations/0006_metrics.rb b/lib/benchmarker/data/migrations/0006_metrics.rb deleted file mode 100644 index f27c39d..0000000 --- a/lib/benchmarker/data/migrations/0006_metrics.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -class Metrics < ActiveRecord::Migration[6.0] - def change - create_table :metrics do |t| - t.references :framework - t.references :value - t.references :concurrency - end - - add_index :metrics, [:framework_id, :value_id, :concurrency_id] - end -end diff --git a/lib/benchmarker/data/models/metric.rb b/lib/benchmarker/data/models/metric.rb deleted file mode 100644 index bfafd8e..0000000 --- a/lib/benchmarker/data/models/metric.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true -module Benchmarker - module Data - class Metric < Model - has_one :framework - has_one :value - has_one :concurrency - end - end -end diff --git a/lib/benchmarker/data/models/language.rb b/lib/benchmarker/data/value.rb similarity index 63% rename from lib/benchmarker/data/models/language.rb rename to lib/benchmarker/data/value.rb index 09ddcc0..eda1d0d 100644 --- a/lib/benchmarker/data/models/language.rb +++ b/lib/benchmarker/data/value.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true + module Benchmarker module Data - class Language < Model - + class Value < Base + belongs_to :key end end end diff --git a/lib/benchmarker/data/version.rb b/lib/benchmarker/data/version.rb index 502a4ad..2615e53 100644 --- a/lib/benchmarker/data/version.rb +++ b/lib/benchmarker/data/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Benchmarker module Data VERSION = "0.0.1"