forced 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: c1b62f3102ad7c3f39bfb99d9b7ea2cec3873f29
4
- data.tar.gz: cabafaba97d16fc8191b4971bb972684ca887cc8
3
+ metadata.gz: 24410ac9c0767e607034525d8168837dc87231bf
4
+ data.tar.gz: 1706c0b98edca3bc8b4e09779c829fdc74c07180
5
5
  SHA512:
6
- metadata.gz: f5716bc3e260313d6db7d072a917fad99fd7ecd2f1c0578ae6fcf03eb9a88de8428d1c522b0cc30432517a08b0cfc1b5371513526b4533e071c1f1ee25c49255
7
- data.tar.gz: 8dd67dc2a93046387c8de356db7038e512533755ec9498e6d01c456862dfbabfd2cd1c29d8ec9058379e4ec2510e13efaa00f4723b66f4cacc27f2223c6724d1
6
+ metadata.gz: 16f9039bfcd3f53f2a91148d28f3c52f8363e2c735eca9e3d76ff9d2c4ca7ae5d2495313e6280d5e7eeb91ba39eb7f03525ba516158daecba4a9e2d723e25a49
7
+ data.tar.gz: 49b535a85af7581037e7db44d8dceaba655db7454e17a38f70c1f074cd0c7d61161d5a422f7540d78648dad963ba260f35411b68bc74cc125c84e4b75024fa10
data/README.md CHANGED
@@ -6,16 +6,45 @@ Read the link below to get some insight.
6
6
 
7
7
  * [Handling Force Update on Mobile Apps / Rusty Neuron](https://rustyneuron.net/2018/07/12/handling-force-update-on-mobile-apps/)
8
8
 
9
- ## Usage
9
+ ## Installation
10
+ Add this line to your application's Gemfile:
10
11
 
11
- Module needs to get the coming request to prepare the response. As long as request headers contains `X-Platform` and `X-Client-Version`, you are good to go.
12
+ ```ruby
13
+ gem 'forced'
14
+ ```
15
+
16
+ And then execute:
17
+ ```bash
18
+ $ bundle
19
+ ```
12
20
 
13
- After adding `forced` to your Gemfile, add the line below to your routes file.
21
+ Or install it yourself as:
22
+ ```bash
23
+ $ gem install forced
24
+ ```
25
+
26
+ And then, run:
27
+ ```bash
28
+ # this will create a migration file.
29
+ $ bundle exec rails g forced:install
30
+
31
+ # this will migrate it.
32
+ $ bundle exec rails db:migrate
33
+ ```
34
+
35
+ After all these are done, add the line below to your routes file.
14
36
 
15
37
  ```ruby
16
38
  mount Forced::Engine => "/forced"
17
39
  ```
18
40
 
41
+ You are all set!
42
+
43
+ ## Usage
44
+
45
+ Module needs to get the coming request to prepare the response. As long as request headers contains `X-Platform` and `X-Client-Version`, you are good to go.
46
+
47
+
19
48
  Then send a `GET` request to `{{url}}/forced/status`. This will return the below JSON.
20
49
 
21
50
  ```json
@@ -52,22 +81,5 @@ Forced::AppVersion.new
52
81
 
53
82
  All available under `Forced::MESSAGES` hash table. You can override the values as you wish. Also checkout the `check_update_status` private method in `base.rb` to understand the cases.
54
83
 
55
- ## Installation
56
- Add this line to your application's Gemfile:
57
-
58
- ```ruby
59
- gem 'forced'
60
- ```
61
-
62
- And then execute:
63
- ```bash
64
- $ bundle
65
- ```
66
-
67
- Or install it yourself as:
68
- ```bash
69
- $ gem install forced
70
- ```
71
-
72
84
  ## License
73
85
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/forced/engine.rb CHANGED
@@ -1,14 +1,5 @@
1
1
  module Forced
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Forced
4
-
5
- # import engine's migratons into main app
6
- initializer :append_migrations do |app|
7
- unless app.root.to_s.match root.to_s
8
- config.paths["db/migrate"].expanded.each do |expanded_path|
9
- app.config.paths["db/migrate"] << expanded_path
10
- end
11
- end
12
- end
13
4
  end
14
5
  end
@@ -1,6 +1,6 @@
1
1
  module Forced
2
2
  MAJOR = 0
3
- MINOR = 1
3
+ MINOR = 2
4
4
  TINY = 0
5
5
  PRE = nil
6
6
 
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/active_record'
5
+
6
+ module Forced
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ include ::Rails::Generators::Migration
9
+
10
+ MYSQL_ADAPTERS = [
11
+ "ActiveRecord::ConnectionAdapters::MysqlAdapter",
12
+ "ActiveRecord::ConnectionAdapters::Mysql2Adapter"
13
+ ].freeze
14
+
15
+ source_root File.expand_path('templates', __dir__)
16
+
17
+ desc "Generates (but does not run) a migration to add a forced_app_versions table."
18
+
19
+ def create_migration_file
20
+ add_paper_trail_migration('create_forced_app_versions')
21
+ end
22
+
23
+ def self.next_migration_number(dirname)
24
+ ::ActiveRecord::Generators::Base.next_migration_number(dirname)
25
+ end
26
+
27
+ protected
28
+
29
+ def add_paper_trail_migration(template)
30
+ migration_dir = File.expand_path('db/migrate')
31
+
32
+ if self.class.migration_exists?(migration_dir, template)
33
+ ::Kernel.warn "Migration already exists: #{template}"
34
+ else
35
+ migration_template(
36
+ "#{template}.rb.erb",
37
+ "db/migrate/#{template}.rb",
38
+ migration_version: migration_version,
39
+ forced_app_versions_table_options: forced_app_versions_table_options
40
+ )
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def migration_version
47
+ major = ActiveRecord::VERSION::MAJOR
48
+ if major >= 5
49
+ "[#{major}.#{ActiveRecord::VERSION::MINOR}]"
50
+ end
51
+ end
52
+
53
+ def mysql?
54
+ MYSQL_ADAPTERS.include?(ActiveRecord::Base.connection.class.name)
55
+ end
56
+
57
+ def forced_app_versions_table_options
58
+ if mysql?
59
+ ', { options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci" }'
60
+ else
61
+ ""
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ # This migration creates the `app_versions` table, the only schema PT requires.
2
+ # All other migrations PT provides are optional.
3
+ class CreateForcedAppVersions < ActiveRecord::Migration<%= migration_version %>
4
+
5
+ def change
6
+ create_table :forced_app_versions<%= forced_app_versions_table_options %> do |t|
7
+ t.integer :client
8
+ t.string :version, limit: 255
9
+ t.boolean :force_update, nil: false, default: false
10
+ t.text :changelog
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aoozdemir
@@ -62,19 +62,11 @@ files:
62
62
  - MIT-LICENSE
63
63
  - README.md
64
64
  - Rakefile
65
- - app/assets/config/forced_manifest.js
66
- - app/assets/javascripts/forced/application.js
67
- - app/assets/stylesheets/forced/application.css
68
65
  - app/controllers/forced/application_controller.rb
69
66
  - app/controllers/forced/status_controller.rb
70
- - app/helpers/forced/application_helper.rb
71
- - app/jobs/forced/application_job.rb
72
- - app/mailers/forced/application_mailer.rb
73
67
  - app/models/forced/app_version.rb
74
68
  - app/models/forced/application_record.rb
75
- - app/views/layouts/forced/application.html.erb
76
69
  - config/routes.rb
77
- - db/migrate/20180713160038_create_forced_app_versions.rb
78
70
  - lib/forced.rb
79
71
  - lib/forced/base.rb
80
72
  - lib/forced/client_enum.rb
@@ -82,6 +74,8 @@ files:
82
74
  - lib/forced/messages.rb
83
75
  - lib/forced/response.rb
84
76
  - lib/forced/version.rb
77
+ - lib/generators/forced/install_generator.rb
78
+ - lib/generators/forced/templates/create_forced_app_versions.rb.erb
85
79
  - lib/tasks/forced_tasks.rake
86
80
  homepage: https://github.com/aoozdemir/forced
87
81
  licenses:
@@ -1,2 +0,0 @@
1
- //= link_directory ../javascripts/forced .js
2
- //= link_directory ../stylesheets/forced .css
@@ -1,15 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
- //
10
- // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require rails-ujs
14
- //= require activestorage
15
- //= require_tree .
@@ -1,15 +0,0 @@
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
- */
@@ -1,4 +0,0 @@
1
- module Forced
2
- module ApplicationHelper
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Forced
2
- class ApplicationJob < ActiveJob::Base
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module Forced
2
- class ApplicationMailer < ActionMailer::Base
3
- default from: 'from@example.com'
4
- layout 'mailer'
5
- end
6
- end
@@ -1,16 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Forced</title>
5
- <%= csrf_meta_tags %>
6
- <%= csp_meta_tag %>
7
-
8
- <%= stylesheet_link_tag "forced/application", media: "all" %>
9
- <%= javascript_include_tag "forced/application" %>
10
- </head>
11
- <body>
12
-
13
- <%= yield %>
14
-
15
- </body>
16
- </html>
@@ -1,12 +0,0 @@
1
- class CreateForcedAppVersions < ActiveRecord::Migration[5.2]
2
- def change
3
- create_table :forced_app_versions do |t|
4
- t.integer :client
5
- t.string :version, limit: 255
6
- t.boolean :force_update, nil: false, default: false
7
- t.text :changelog
8
-
9
- t.timestamps
10
- end
11
- end
12
- end