Skip to content

Commit

Permalink
Merge pull request #16 from geoblacklight/update-ci
Browse files Browse the repository at this point in the history
Update the gem
  • Loading branch information
cbeer authored Jun 4, 2024
2 parents b4cad62 + 11e8d34 commit 28d6199
Show file tree
Hide file tree
Showing 36 changed files with 215 additions and 172 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: ['3.0']
rails_version: [6.0.3.4, 6.1.1, 7.0.3]
include:
- ruby: '3.1'
rails_version: 7.0.3
- ruby: 2.7
rails_version: 6.1.1
ruby: ['3.1', '3.2']
rails_version: [6.1.7.8, 7.0.8.4]
env:
RAILS_VERSION: ${{ matrix.rails_version }}
steps:
Expand Down
33 changes: 33 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require:
- rubocop-rspec
- rubocop-rails
- rubocop-rspec_rails

AllCops:
TargetRubyVersion: 3.2
DisplayCopNames: true
Exclude:
- "Gemfile"
- "*.gemspec"
- "bin/**/*"
- "db/**/*"
- "tmp/**/*"
- "storage/**/*"
- "node_modules/**/*"
- "vendor/**/*"

Rails:
Enabled: true

Metrics/AbcSize:
Enabled: false
Metrics/MethodLength:
Enabled: false
Layout/LineLength:
Enabled: false
RSpec/ExampleLength:
Enabled: false
RSpec/MultipleExpectations:
Enabled: false
Naming/VariableNumber:
EnforcedStyle: snake_case
23 changes: 11 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ gemspec
# To use a debugger
# gem 'byebug', group: [:development, :test]
# BEGIN ENGINE_CART BLOCK
# engine_cart: 1.2.0
# engine_cart stanza: 0.10.0
# engine_cart: 2.6.0
# engine_cart stanza: 2.5.0
# the below comes from engine_cart, a gem used to test this Rails engine gem in the context of a Rails app.
file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app', File.dirname(__FILE__)))
if File.exist?(file)
Expand All @@ -34,17 +34,16 @@ else
else
gem 'rails', ENV['RAILS_VERSION']
end
end

case ENV['RAILS_VERSION']
when /^5.[12]/
gem 'sass-rails', '~> 5.0'
when /^4.2/
gem 'responders', '~> 2.0'
gem 'sass-rails', '>= 5.0'
gem 'coffee-rails', '~> 4.1.0'
when /^4.[01]/
gem 'sass-rails', '< 5.0'
case ENV['RAILS_VERSION']
when /^6.0/
gem 'sass-rails', '>= 6'
gem 'webpacker', '~> 4.0'
when /^5.[12]/
gem 'sass-rails', '~> 5.0'
gem 'sprockets', '~> 3.7'
gem 'thor', '~> 0.20'
end
end
end
# END ENGINE_CART BLOCK
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# GeoMonitor
Short description and motivation.
A Rails engine for monitoring geospatial web services.

## Usage
How to use my plugin.
Expand All @@ -13,16 +13,24 @@ gem 'geo_monitor'

And then execute:
```bash
$ bundle
bundle
```

Or install it yourself as:
```bash
$ gem install geo_monitor
gem install geo_monitor
```

## Contributing
Contribution directions go here.
## Developing
Set up the internal test app using `engine_cart`:
```bash
rake engine_cart:generate
```

Run the test suite, including RuboCop style checks:
```bash
rake ci
```

## License
The gem is available as open source under the terms of the [Apache License 2.0](https://opensource.org/licenses/Apache-2.0).
23 changes: 8 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

begin
require 'bundler/setup'
rescue LoadError
Expand All @@ -6,23 +8,14 @@ end

require 'bundler/gem_tasks'
require 'engine_cart/rake_task'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

namespace :geomonitor do
desc 'Create the test rails app'
task generate: ['engine_cart:generate'] do
end
end
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:rubocop) { |task| task.fail_on_error = true }

task ci: ['geomonitor:generate'] do
task ci: [:rubocop, 'engine_cart:generate'] do
Rake::Task['spec'].invoke
end

begin
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: :ci
rescue LoadError
# no rspec available
end
task default: :ci
2 changes: 0 additions & 2 deletions app/assets/config/geo_monitor_manifest.js

This file was deleted.

Empty file.
13 changes: 0 additions & 13 deletions app/assets/javascripts/geo_monitor/application.js

This file was deleted.

15 changes: 0 additions & 15 deletions app/assets/stylesheets/geo_monitor/application.css

This file was deleted.

5 changes: 0 additions & 5 deletions app/controllers/geo_monitor/application_controller.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/helpers/geo_monitor/application_helper.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/jobs/geo_monitor/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GeoMonitor
class ApplicationJob < ActiveJob::Base
end
Expand Down
6 changes: 0 additions & 6 deletions app/mailers/geo_monitor/application_mailer.rb

This file was deleted.

3 changes: 3 additions & 0 deletions app/models/geo_monitor/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

module GeoMonitor
# Base class for all models in the engine
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Expand Down
3 changes: 3 additions & 0 deletions app/models/geo_monitor/geo_monitor.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

module GeoMonitor
# Generic database config for the engine
module GeoMonitor
def self.table_name_prefix
'geo_monitor_geo_monitor_'
Expand Down
7 changes: 5 additions & 2 deletions app/models/geo_monitor/layer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# frozen_string_literal: true

module GeoMonitor
# A single layer in a GeoBlacklight instance
class Layer < ApplicationRecord
has_many :statuses
has_many :statuses, dependent: :destroy

##
# @param [String] schema_json
Expand Down Expand Up @@ -32,7 +35,7 @@ def check
response = nil
time = Benchmark.measure do
response = ::GeoMonitor::Requests::WMS.new(
bbox: bounding_box, url: url, layers: layername
bbox: bounding_box, url:, layers: layername
).tile
end
::GeoMonitor::Status.from_response(response, self, time.real.to_f)
Expand Down
13 changes: 9 additions & 4 deletions app/models/geo_monitor/status.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# frozen_string_literal: true

module GeoMonitor
# A record of availability for a single layer at a single point in time
class Status < ApplicationRecord
belongs_to :layer, counter_cache: true, touch: true
before_create :limit_by_layer

##
# Limits the number of statuses per layer to prevent a ballooing database
def limit_by_layer
statuses_by_layer = self.class.where(layer: layer).count
statuses_by_layer = self.class.where(layer:).count
max = ::GeoMonitor::Engine.config.max_status_per_layer
return unless statuses_by_layer >= max

self.class
.where(layer: layer)
.where(layer:)
.first(statuses_by_layer - max + 1)
.map(&:destroy) if statuses_by_layer >= max
.map(&:destroy)
end

##
Expand All @@ -23,7 +28,7 @@ def self.from_response(response, layer, time)
res_time: time.to_f,
res_code: response.status,
submitted_query: response.env[:url].to_s,
layer: layer,
layer:,
res_headers: response.headers,
content_type: response.headers.try(:[], :content_type)
)
Expand Down
14 changes: 0 additions & 14 deletions app/views/layouts/geo_monitor/application.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions config/routes.rb

This file was deleted.

8 changes: 6 additions & 2 deletions geo_monitor.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ Gem::Specification.new do |s|

s.files = Dir['{app,config,db,lib}/**/*', 'LICENSE', 'Rakefile', 'README.md']

s.add_dependency 'rails', '>= 5.2', '< 7.2'
s.add_dependency 'rails', '>= 6.1', '< 7.2'
s.add_dependency 'faraday'

s.add_development_dependency 'engine_cart', '~> 2.0'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'webmock'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rspec-rails'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'rubocop-rspec'
s.add_development_dependency 'rubocop-rails'
end
4 changes: 3 additions & 1 deletion lib/generators/geo_monitor/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

module GeoMonitor
##
# GeoMonitor Installer
class Install < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
source_root File.expand_path('templates', __dir__)
end
end
6 changes: 4 additions & 2 deletions lib/geo_monitor.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require "geo_monitor/engine"
# frozen_string_literal: true

require 'geo_monitor/engine'

# Main module for the engine
module GeoMonitor
extend ActiveSupport::Autoload


# A simple structure to conform to Faraday::Response
FailedResponse = Struct.new(:env, :status, :headers)
end
4 changes: 3 additions & 1 deletion lib/geo_monitor/bounding_box.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GeoMonitor
##
# Bounding Box
Expand Down Expand Up @@ -59,7 +61,7 @@ def tile_number
else
x
end
{ x: x, y: y }
{ x:, y: }
end
end
end
2 changes: 2 additions & 0 deletions lib/geo_monitor/constants.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module GeoMonitor
module Constants
R = 6_378_137 # Radius of Earth in meters
Expand Down
2 changes: 2 additions & 0 deletions lib/geo_monitor/engine.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rails/all'
require 'faraday'

Expand Down
6 changes: 5 additions & 1 deletion lib/geo_monitor/lat_lng_point.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

module GeoMonitor
# A point in space with latitude and longitude
class LatLngPoint
attr_accessor :lat, :lng

def initialize(lat: 0, lng: 0)
@lat = lat.to_f
@lng = lng.to_f
Expand All @@ -26,7 +30,7 @@ def self.from_number(xtile, ytile, zoom)
lng = xtile / n * 360.0 - 180.0
lat_rad = Math.atan(Math.sinh(Math::PI * (1 - 2 * ytile / n)))
lat = 180.0 * (lat_rad / Math::PI)
new(lat: lat, lng: lng)
new(lat:, lng:)
end
end
end
Loading

0 comments on commit 28d6199

Please sign in to comment.