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 +4 -4
- data/README.md +20 -0
- data/app/models/concerns/summarize.rb +2 -2
- data/app/models/twinkle/app.rb +1 -14
- data/app/models/twinkle/summary.rb +5 -2
- data/app/models/twinkle/version.rb +7 -5
- data/db/migrate/20240517232121_create_twinkle_versions.rb +1 -1
- data/db/migrate/20240517234016_create_twinkle_summaries.rb +1 -1
- data/db/migrate/20240530023848_add_published_to_twinkle_versions.rb +6 -0
- data/lib/twinkle/concerns/models/app.rb +24 -0
- data/lib/twinkle/version.rb +1 -1
- data/lib/twinkle.rb +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11aec611ab42595799ef8573c3c4531ddc4de266cc493f6e489259d14c0bb4be
|
4
|
+
data.tar.gz: 47e2fb84ddc979e4cd5c9389c578f71c28d4c080c8732ae5368638352b4bbaea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|
data/app/models/twinkle/app.rb
CHANGED
@@ -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?
|
@@ -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
|
data/lib/twinkle/version.rb
CHANGED
data/lib/twinkle.rb
CHANGED
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.
|
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
|