luck_remover 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bc1b1530a599ee139347208b43f1c6fd6366c9ab7f78024702a5d8cc79293325
4
+ data.tar.gz: 2c99268c938c575639ff6fe9a06b098e7a419cfe17824d632d631fc462d7338e
5
+ SHA512:
6
+ metadata.gz: 9686dd5a3997e32c8045db01e564146f8d67cc5d612bef475d69a505c7a3a5eece606f52bfb0a90b80a282453158c2d26dd6fb3a657bf849c69ba37f43e1b9bf
7
+ data.tar.gz: 0c01f0d6f8dcbda67ccb8fb1096b7bada0713bc202792771e5c3edd27abaa71f027df33c3e9ca6877446e369a3fe8e4f60876053d06b4ea2936f2b09c48b86fc
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright TODO: Write your name
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # luck_remover
2
+
3
+ Goals set against an app's own metrics.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ require "bundler/gem_tasks"
7
+ require "rake/testtask"
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << "test"
11
+ t.libs << "lib"
12
+ t.test_files = FileList["test/**/*_test.rb"]
13
+ end
14
+
15
+ task default: :test
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module LuckRemover
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module LuckRemover
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module LuckRemover
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module LuckRemover
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module LuckRemover
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ require "cs133"
2
+
3
+ module LuckRemover
4
+ class Goal < ApplicationRecord
5
+ belongs_to :owner, polymorphic: true
6
+
7
+ scope :for_owner, ->(owner) { where(owner: owner) }
8
+
9
+ enum :direction, { at_least: "at_least", at_most: "at_most" }, validate: true
10
+ enum :period, { week: "week", month: "month" }, validate: true
11
+
12
+ validate :metric_is_registered
13
+
14
+ def standing(now: Time.current)
15
+ value = LuckRemover.metric(metric_key).read(range: current_period(now)).value
16
+ Standing.new(value: value, target: target, direction: direction)
17
+ end
18
+
19
+ private
20
+
21
+ def current_period(now)
22
+ range = month? ? Cs133::Range.this_month(zone: Time.zone, now: now) : Cs133::Range.last_weeks(1, zone: Time.zone, now: now).first
23
+ range.to_range
24
+ end
25
+
26
+ def metric_is_registered
27
+ return if LuckRemover.metrics.registered?(metric_key.to_s)
28
+
29
+ errors.add(:metric_key, "#{metric_key} is not a registered goal metric")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ module LuckRemover
2
+ Standing = Data.define(:value, :target, :direction) do
3
+ def met?
4
+ direction.to_s == "at_most" ? value <= target : value >= target
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Luck remover</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= yield :head %>
9
+
10
+ <%= stylesheet_link_tag "luck_remover/application", media: "all" %>
11
+ </head>
12
+ <body>
13
+
14
+ <%= yield %>
15
+
16
+ </body>
17
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ LuckRemover::Engine.routes.draw do
2
+ end
@@ -0,0 +1,14 @@
1
+ class CreateLuckRemoverGoals < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :luck_remover_goals do |t|
4
+ t.references :owner, polymorphic: true, null: false
5
+ t.string :name
6
+ t.string :metric_key
7
+ t.decimal :target
8
+ t.string :direction
9
+ t.string :period
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module LuckRemover
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace LuckRemover
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LuckRemover
4
+ class DuplicateMetricError < StandardError; end
5
+
6
+ class MetricRegistry
7
+ def initialize
8
+ @stats = {}
9
+ end
10
+
11
+ def register(stat)
12
+ key = stat.key.to_sym
13
+ raise DuplicateMetricError, "A goal metric is already registered under #{key}" if registered?(key)
14
+
15
+ @stats[key] = stat
16
+ end
17
+
18
+ def registered?(key)
19
+ @stats.key?(key.to_sym)
20
+ end
21
+
22
+ def fetch(key)
23
+ @stats.fetch(key.to_sym)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module LuckRemover
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,22 @@
1
+ require "readout"
2
+ require "luck_remover/version"
3
+ require "luck_remover/engine"
4
+ require "luck_remover/metric_registry"
5
+
6
+ module LuckRemover
7
+ def self.metrics
8
+ @metrics ||= MetricRegistry.new
9
+ end
10
+
11
+ def self.register_metric(stat)
12
+ metrics.register(stat)
13
+ end
14
+
15
+ def self.metric(key)
16
+ metrics.fetch(key)
17
+ end
18
+
19
+ def self.reset_metrics!
20
+ @metrics = MetricRegistry.new
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :luck_remover do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: luck_remover
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Schneider
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.1'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: readout
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.1.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 0.1.0
40
+ - !ruby/object:Gem::Dependency
41
+ name: cs133
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.0
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.0
54
+ description: LuckRemover stores goals that name a registered readout Stat, a target,
55
+ a direction and a period, and reports whether the current period met each one.
56
+ email:
57
+ - tylercschneider@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/assets/stylesheets/luck_remover/application.css
66
+ - app/controllers/luck_remover/application_controller.rb
67
+ - app/helpers/luck_remover/application_helper.rb
68
+ - app/jobs/luck_remover/application_job.rb
69
+ - app/mailers/luck_remover/application_mailer.rb
70
+ - app/models/luck_remover/application_record.rb
71
+ - app/models/luck_remover/goal.rb
72
+ - app/models/luck_remover/standing.rb
73
+ - app/views/layouts/luck_remover/application.html.erb
74
+ - config/routes.rb
75
+ - db/migrate/20261022212722_create_luck_remover_goals.rb
76
+ - lib/luck_remover.rb
77
+ - lib/luck_remover/engine.rb
78
+ - lib/luck_remover/metric_registry.rb
79
+ - lib/luck_remover/version.rb
80
+ - lib/tasks/luck_remover_tasks.rake
81
+ homepage: https://github.com/DYB-Development/luck_remover
82
+ licenses:
83
+ - MIT
84
+ metadata:
85
+ homepage_uri: https://github.com/DYB-Development/luck_remover
86
+ source_code_uri: https://github.com/DYB-Development/luck_remover
87
+ changelog_uri: https://github.com/DYB-Development/luck_remover/blob/main/CHANGELOG.md
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: 3.3.0
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 4.0.20
103
+ specification_version: 4
104
+ summary: A Rails engine for goals set against an app's own metrics.
105
+ test_files: []