twinkle 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8ac554f1dff3ef39f4915f981ec076b50702272d4e580fd53c883065b01c430
4
- data.tar.gz: dc5f679b7366c31e316f067886298f5408b32d11706bdd56de76a95ad6550685
3
+ metadata.gz: 11aec611ab42595799ef8573c3c4531ddc4de266cc493f6e489259d14c0bb4be
4
+ data.tar.gz: 47e2fb84ddc979e4cd5c9389c578f71c28d4c080c8732ae5368638352b4bbaea
5
5
  SHA512:
6
- metadata.gz: 37eaf8576e4d1b47332eb5fd48c082cb08b75df2578bba102308d5d74e550e3964bbae168a462297e4af2b78f9f78d5a9f0cbe1c2041cc9236f38b13d8ebeaa2
7
- data.tar.gz: 9fcf89b14a7a6b945fe607af393db115f79d28b29a4d33585844b82009455103871060dffcc41e0017ef597ef6a05a92091410fd012fc30964fb7d1156a25181
6
+ metadata.gz: 8459279d6a1ee5d1f4ad47df0da68948024ef60d95cdf86ded42ac77f54c636149de394dbb69fd23b78fe2f9764d7cea8f10dad066d3d159047de96ce222092b
7
+ data.tar.gz: adf1ab532210ac62d886c5a769c03d282aecef5bb25714bfa51af27293c1bc516f7c5dc483c5dcd984e90faea8c7895eea9705bc3cfbccc369ad2febc07e11f7
data/README.md CHANGED
@@ -46,10 +46,30 @@ mount Twinkle::Engine => "/"
46
46
 
47
47
  This will mount the appcast routes at /updates/:app.slug
48
48
 
49
+ ## Extending Twinkle Apps
50
+
51
+ You can extend the Twinkle::App model by creating app/models/twinkle/app.rb
52
+
53
+ ```ruby
54
+ class Twinkle::App < ApplicationRecord
55
+ include Twinkle::Concerns::Models::App
56
+ include Summarize
57
+
58
+ # Your custom app code and validations etc go here
59
+ end
60
+ ```
61
+
49
62
  ## Contributing
50
63
 
51
64
  Pull requests welcome.
52
65
 
66
+ ## Building the gem
67
+
68
+ ```bash
69
+ gem build
70
+ gem push twinkle-x.x.x.gem
71
+ ```
72
+
53
73
  ## License
54
74
 
55
75
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -4,7 +4,7 @@ module Summarize
4
4
  included do
5
5
  def summarize_events(period, start_date, end_date)
6
6
  # Find or create a summary for the week
7
- summary = Twinkle::Summary.with_datapoints.find_or_create_by(app: self, period: period, start_date: start_date, end_date: end_date)
7
+ summary = Twinkle::Summary.find_or_create_by(app: self, period: period, start_date: start_date, end_date: end_date)
8
8
  data_hash = get_data_hash(start_date, end_date)
9
9
  datapoints = get_datapoints(summary, data_hash)
10
10
  save_summary(datapoints)
@@ -17,7 +17,7 @@ module Summarize
17
17
  events.created_between(start_date, end_date).find_each do |event|
18
18
  data_hash['users']['sessions'] = (data_hash.dig('users', 'sessions') || 0) + 1
19
19
  Twinkle::Event.fields.each do |field|
20
- data_hash[field][event[field]] = (data_hash.dig(field, event[field]) || 0) + 1
20
+ data_hash[field][event[field]] = (data_hash.dig(field, event[field]) || 0) + 1 if event[field].present?
21
21
  end
22
22
  end
23
23
  data_hash
@@ -1,19 +1,6 @@
1
1
  module Twinkle
2
2
  class App < ApplicationRecord
3
+ include Twinkle::Concerns::Models::App
3
4
  include Summarize
4
-
5
- has_many :versions, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Version'
6
- has_many :events, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Event'
7
- has_many :summaries, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Summary'
8
- has_one_attached :icon
9
-
10
- scope :with_versions, -> { includes(:versions).order('twinkle_versions.build desc') }
11
- scope :with_latest_version, -> { includes(:versions).order('twinkle_versions.build desc').limit(1) }
12
- scope :with_latest_summary, -> { includes(:summaries).order('twinkle_summaries.created_at desc').limit(1) }
13
- scope :with_summaries_since, ->(date) { includes(:summaries).where('twinkle_summaries.start >= ?', date).order('twinkle_summaries.start asc') }
14
-
15
- validates :name, presence: true
16
- validates :slug, presence: true, uniqueness: true
17
- validates :description, presence: true
18
5
  end
19
6
  end
@@ -1,10 +1,13 @@
1
1
  module Twinkle
2
2
  class Summary < ApplicationRecord
3
3
  belongs_to :app, foreign_key: :twinkle_app_id, class_name: 'Twinkle::App'
4
- has_many :datapoints, foreign_key: :twinkle_summary_id, class_name: 'Twinkle::Datapoint'
4
+ has_many :datapoints, foreign_key: :twinkle_summary_id, class_name: 'Twinkle::Datapoint', dependent: :delete_all
5
5
 
6
+ # Virtual relationships
7
+ has_one :latest_user_summary, -> { where(name: 'users').order('twinkle_datapoints.value desc').limit(1) }, foreign_key: :twinkle_summary_id, class_name: 'Twinkle::Datapoint'
8
+
9
+ scope :since, ->(date) { where('twinkle_summaries.start_date >= ?', date).order('twinkle_summaries.start_date asc') }
6
10
  scope :week_of, -> (start_date, end_date) { where(period: :week).where("start_date >= ? AND end_date <= ?", start_date, end_date) }
7
- scope :with_datapoints, -> { includes(:datapoints) }
8
11
 
9
12
  enum period: { week: 0, fortnight: 1, month: 2 }
10
13
 
@@ -6,20 +6,22 @@ module Twinkle
6
6
 
7
7
  validates :number, presence: true
8
8
  validates :build, presence: true
9
- validates :description, presence: true
10
- validates :binary_url, presence: true
11
- validates :length, presence: true
12
- validates :length, numericality: { only_integer: true, greater_than: 0 }
9
+ validates :description, presence: true, if: -> { published }
10
+ validates :binary_url, presence: true, if: -> { published }
11
+ validates :length, presence: true, if: -> { published }
12
+ validates :length, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true
13
+
13
14
 
14
15
  # validates that the binary_url is a valid URL
15
16
  validate :binary_url_is_url
16
17
 
17
18
  # validates that one of the two signatures is present
18
- validate :signature_present
19
+ validate :signature_present, if: -> { published }
19
20
 
20
21
  private
21
22
 
22
23
  def binary_url_is_url
24
+ return true if binary_url.blank?
23
25
  begin
24
26
  uri = URI.parse(binary_url)
25
27
  raise URI::InvalidURIError unless uri.is_a?(URI::HTTP) && uri.host.present?
@@ -12,6 +12,6 @@ class CreateTwinkleVersions < ActiveRecord::Migration[7.1]
12
12
 
13
13
  t.timestamps
14
14
  end
15
- add_index :twinkle_versions, :build
15
+ add_index :twinkle_versions, [:twinkle_app_id, :build], unique: true
16
16
  end
17
17
  end
@@ -8,6 +8,6 @@ class CreateTwinkleSummaries < ActiveRecord::Migration[7.1]
8
8
 
9
9
  t.timestamps
10
10
  end
11
- add_index :twinkle_summaries, [:period, :start_date, :end_date]
11
+ add_index :twinkle_summaries, [:period, :start_date, :end_date], unique: true
12
12
  end
13
13
  end
@@ -0,0 +1,6 @@
1
+ class AddPublishedToTwinkleVersions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :twinkle_versions, :published, :boolean, default: false, null: false
4
+ add_index :twinkle_versions, [:twinkle_app_id, :published]
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ module Twinkle
2
+ module Concerns
3
+ module Models
4
+ module App
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ has_many :versions, -> { order('twinkle_versions.build desc') }, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Version', dependent: :destroy
9
+ has_many :events, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Event', dependent: :delete_all
10
+ has_many :summaries, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Summary', dependent: :destroy
11
+ has_one_attached :icon
12
+
13
+ # Virtual relationships
14
+ has_one :latest_version, -> { order('twinkle_versions.build desc').limit(1) }, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Version'
15
+ has_one :latest_weekly_summary, -> { where(period: :week).order('twinkle_summaries.start_date desc').limit(1) }, foreign_key: 'twinkle_app_id', class_name: 'Twinkle::Summary'
16
+
17
+ validates :name, presence: true
18
+ validates :slug, presence: true, uniqueness: true
19
+ validates :description, presence: true
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Twinkle
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/twinkle.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "twinkle/version"
2
2
  require "twinkle/engine"
3
+ require "twinkle/concerns/models/app"
3
4
 
4
5
  module Twinkle
5
6
  # Your code goes here...
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twinkle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Marks
@@ -57,12 +57,15 @@ files:
57
57
  - db/migrate/20240517233457_create_twinkle_events.rb
58
58
  - db/migrate/20240517234016_create_twinkle_summaries.rb
59
59
  - db/migrate/20240518000405_create_twinkle_datapoints.rb
60
+ - db/migrate/20240530023848_add_published_to_twinkle_versions.rb
60
61
  - lib/tasks/twinkle_tasks.rake
61
62
  - lib/twinkle.rb
63
+ - lib/twinkle/concerns/models/app.rb
62
64
  - lib/twinkle/engine.rb
63
65
  - lib/twinkle/version.rb
64
66
  homepage: https://github.com/imothee/twinkle
65
- licenses: []
67
+ licenses:
68
+ - MIT
66
69
  metadata:
67
70
  allowed_push_host: https://rubygems.org/
68
71
  homepage_uri: https://github.com/imothee/twinkle