is_published 0.1.2 → 0.1.3

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: 7a19de810fed315d96c0bab71b45d4040cc117fdd718c81f5a1e85a8c94d971d
4
- data.tar.gz: b1198cd1dc86c45b9e48c77c437f9f180365e03bfd99794d68d3f867384f0f9c
3
+ metadata.gz: ed08f98a881c6c1ee29ca1ab7d5d29d3e07af03b62aaf585ac3573dd4a1ed2ee
4
+ data.tar.gz: 6bdd2c7f1e06031d41acb8076c064f798c025b954fd9c3845b737d4bf9ea3447
5
5
  SHA512:
6
- metadata.gz: 5eab8e3e239c2f5f06f3619ebc90814901cd9be2a9e490ce44617a417ba5a5cc3a3ac9a6d34d0decac36cc007232810523dd52f9f382c52bf2439f49a2b68fa4
7
- data.tar.gz: cfa2e0fc0d819ef1a510ccc7865a493cad546fce815c6015e4c26311488919a9db727adbe6e69bae2c50ce285cc688f4f2d4094570689ad94f032800eaf70a8f
6
+ metadata.gz: 04144ce97523798522224e2a5ffaa1b0ac4a932ed15f6dd5b80494d99fb2087f2b9852c40283b4e9de858719c5b86564038ced5da42d2892a848fdf6c3ee5c6a
7
+ data.tar.gz: 5cd3d92e8f430d67e966b999550cb4adc419b67dc81b0d277b9840583c422a9f575ea07bca4970a8c15ef85d10b08be301d2b184303721e86166345f3bb59c24
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
 
13
13
  \.idea/
14
+
15
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,12 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- is_published (0.1.2)
4
+ is_published (0.1.3)
5
5
  activerecord (>= 3.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ actionpack (5.2.3)
11
+ actionview (= 5.2.3)
12
+ activesupport (= 5.2.3)
13
+ rack (~> 2.0)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+ actionview (5.2.3)
18
+ activesupport (= 5.2.3)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
10
23
  activemodel (5.2.3)
11
24
  activesupport (= 5.2.3)
12
25
  activerecord (5.2.3)
@@ -19,11 +32,38 @@ GEM
19
32
  minitest (~> 5.1)
20
33
  tzinfo (~> 1.1)
21
34
  arel (9.0.0)
35
+ builder (3.2.3)
22
36
  concurrent-ruby (1.1.5)
37
+ crass (1.0.4)
23
38
  diff-lcs (1.3)
39
+ erubi (1.8.0)
40
+ generator_spec (0.9.4)
41
+ activesupport (>= 3.0.0)
42
+ railties (>= 3.0.0)
24
43
  i18n (1.6.0)
25
44
  concurrent-ruby (~> 1.0)
45
+ loofah (2.2.3)
46
+ crass (~> 1.0.2)
47
+ nokogiri (>= 1.5.9)
48
+ method_source (0.9.2)
49
+ mini_portile2 (2.4.0)
26
50
  minitest (5.11.3)
51
+ nokogiri (1.10.3)
52
+ mini_portile2 (~> 2.4.0)
53
+ rack (2.0.7)
54
+ rack-test (1.1.0)
55
+ rack (>= 1.0, < 3)
56
+ rails-dom-testing (2.0.3)
57
+ activesupport (>= 4.2.0)
58
+ nokogiri (>= 1.6)
59
+ rails-html-sanitizer (1.0.4)
60
+ loofah (~> 2.2, >= 2.2.2)
61
+ railties (5.2.3)
62
+ actionpack (= 5.2.3)
63
+ activesupport (= 5.2.3)
64
+ method_source
65
+ rake (>= 0.8.7)
66
+ thor (>= 0.19.0, < 2.0)
27
67
  rake (10.5.0)
28
68
  rspec (3.8.0)
29
69
  rspec-core (~> 3.8.0)
@@ -39,6 +79,7 @@ GEM
39
79
  rspec-support (~> 3.8.0)
40
80
  rspec-support (3.8.0)
41
81
  sqlite3 (1.4.0)
82
+ thor (0.20.3)
42
83
  thread_safe (0.3.6)
43
84
  tzinfo (1.2.5)
44
85
  thread_safe (~> 0.1)
@@ -48,6 +89,7 @@ PLATFORMS
48
89
 
49
90
  DEPENDENCIES
50
91
  bundler (~> 2.0)
92
+ generator_spec
51
93
  is_published!
52
94
  rake (~> 10.0)
53
95
  rspec (~> 3.2)
data/README.md CHANGED
@@ -18,8 +18,56 @@ Or install it manually on local machine
18
18
 
19
19
  $ gem install is_published
20
20
 
21
- ## Usage
22
- Before all, class you want to extend with this gem, needs to have column 'published' in the database.
21
+ ## Model and migrations
22
+ ##### Before all. Class you want to extend with this gem, needs to have column 'published' in the database.
23
+
24
+ ###-- If you dont have created migrations and model
25
+
26
+ Gem comes with migrations and model generator, you can create one with this command:
27
+
28
+ ```ruby
29
+ rails g is_published:install [MODEL NAME]
30
+ ```
31
+
32
+ For example:
33
+
34
+ rails g is_published:install Article
35
+
36
+ which will create model and migrations with provided name.
37
+
38
+ Migration will look like this
39
+ ```ruby
40
+ class CreateArticles < ActiveRecord::Migration
41
+ def change
42
+ create_table :articles do |t|
43
+ t.string :title
44
+ t.string :body
45
+ t.boolean :published, default: false
46
+ t.timestamps
47
+ end
48
+ end
49
+ end
50
+ ```
51
+ Model class comes with already extended gem scope, its going to look like this one
52
+
53
+ ```ruby
54
+ class Article < ApplicationRecord
55
+ extend IsPublished::Scopes
56
+ end
57
+ ```
58
+
59
+ If needed, you can customize migrations before running them.
60
+
61
+ After running generator command, run migration.
62
+
63
+ rails db:migrate
64
+
65
+ ####And you are good to go! Proceed to gem usage information!
66
+
67
+
68
+
69
+ ***
70
+ ## -- If you have already model and migrations
23
71
 
24
72
  If your model table already exists, you can create migration to add published column like this:
25
73
 
@@ -49,8 +97,10 @@ class Post < ApplicationRecord
49
97
  end
50
98
  ```
51
99
 
52
- Then you can use it like every other scope
100
+ Now you are done.
53
101
 
102
+ ## Gem usage
103
+ After you are done with migrations and model setup, you can use published scope like this.
54
104
  ```ruby
55
105
  Post.published
56
106
  #=> => #<Post id: 1, title: "Published post", user_id: 1, published: true, created_at: "2019-06-07 14:42:22", updated_at: "2019-06-07 16:51:07">
data/is_published.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ["lib"]
26
26
 
27
27
  spec.add_dependency "activerecord", ">= 3.0"
28
+ spec.add_development_dependency 'generator_spec'
28
29
  spec.add_development_dependency 'sqlite3'
29
30
  spec.add_development_dependency "bundler", "~> 2.0"
30
31
  spec.add_development_dependency "rake", "~> 10.0"
data/lib/is_published.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "is_published/version"
2
2
  require "is_published/scopes"
3
+ require "is_published/generators/install_generator"
3
4
  require 'active_record'
4
5
 
5
6
  module IsPublished
@@ -0,0 +1,31 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module IsPublished
5
+ module Generators
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ source_root File.expand_path('../templates', __FILE__)
9
+ desc "Add the migrations for IsPublished"
10
+ argument :model_name, type: :string, default: 'post'
11
+
12
+ def self.next_migration_number(path)
13
+ next_migration_number = current_migration_number(path) + 1
14
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
15
+ end
16
+
17
+ def copy_migrations
18
+ migration_template "create_migration.erb",
19
+ "db/migrate/create_#{model_name.underscore.pluralize}.rb"
20
+ end
21
+
22
+ def create_model
23
+ create_file "app/models/#{model_name.underscore}.rb", "
24
+ class #{model_name.capitalize} < ApplicationRecord
25
+ extend IsPublished::Scopes
26
+ end
27
+ "
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ class Create<%= model_name.capitalize.pluralize %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= model_name.underscore.pluralize %> do |t|
4
+ t.string :title
5
+ t.string :body
6
+ t.boolean :published, default: false
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module IsPublished
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: is_published
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacek Kowalski
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: generator_spec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: sqlite3
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +116,8 @@ files:
102
116
  - bin/setup
103
117
  - is_published.gemspec
104
118
  - lib/is_published.rb
119
+ - lib/is_published/generators/install_generator.rb
120
+ - lib/is_published/generators/templates/create_migration.erb
105
121
  - lib/is_published/scopes.rb
106
122
  - lib/is_published/version.rb
107
123
  homepage: https://github.com/Eviath/is_published.git