Skip to content

Commit

Permalink
feat: Add models
Browse files Browse the repository at this point in the history
  • Loading branch information
waghanza committed Mar 19, 2020
1 parent e97b03a commit dd0549b
Show file tree
Hide file tree
Showing 27 changed files with 260 additions and 69 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
AllCops:
TargetRubyVersion: 2.6
EnabledByDefault: true

Style:
Enabled: false

Layout:
Enabled: false
74 changes: 74 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -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 [email protected]. 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/
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

source("https://rubygems.org")

gemspec

group :development, :test do
# Keep code consistency
gem "rubocop"
end
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
30 changes: 30 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions benchmarker-data.gemspec
Original file line number Diff line number Diff line change
@@ -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 = ["[email protected]"]

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
29 changes: 0 additions & 29 deletions benchmarker_data.gemspec

This file was deleted.

8 changes: 8 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require('bundler/setup')
require('benchmarker/data')

require('irb')
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions db/migrations/0006_metrics.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions lib/benchmarker/data.rb
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

module Benchmarker
module Data
class Concurrency < Model
class Concurrency < Base
end
end
end
9 changes: 9 additions & 0 deletions lib/benchmarker/data/framework.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Benchmarker
module Data
class Framework < Base
belongs_to :language
end
end
end
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# frozen_string_literal: true

module Benchmarker
module Data
class Key < Model
class Language < Base
end
end
end
11 changes: 11 additions & 0 deletions lib/benchmarker/data/metric.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 0 additions & 13 deletions lib/benchmarker/data/migrations/0006_metrics.rb

This file was deleted.

Loading

0 comments on commit dd0549b

Please sign in to comment.