has_sti 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a7d16773fe76443cfa47a9c55825af2639a01b3
4
- data.tar.gz: 084dfbfb2fb7b3287a074dde9c013a4a60f279a6
3
+ metadata.gz: ea0040619f3cb8b6652c5d0ce175507e722745f0
4
+ data.tar.gz: 2e96af8496677844dbc7fa4b8e9c94f65de39faa
5
5
  SHA512:
6
- metadata.gz: 6422d27461eb2880de4d260d859dcdc07a87b651196db1b14c2ad375b0e02069eb0ef064d177b8c13b00165da1d58739fa91830e07f9b2695622c8d0ab653c5a
7
- data.tar.gz: 43b2c593bd7d9136c5bd2eb188c7bd5a9db8d3e9b2f92656e92fef7ca8060fdd348fd5a670cc6ef9a7183ccc173af7dfe38ba158380f9d449c7f4f4b857ac566
6
+ metadata.gz: 29ac88e68d10fd904e494638f7f22daf97e162a6bc83676136617def12086b0f3b974b6bed4d6753b0381366d06eaa5e43fa3a0171b0759e779f4d32d03e1eea
7
+ data.tar.gz: 1edaf227ebe31fa16a194249e9cf2d6e5c615ad6d005a14481e37f723ecbd0fbbf50c4258bf5473e30f5486eefb4ac998a4a75dbb29014f022361f81e157829d
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ [<img src="https://travis-ci.org/arekf/has_sti.svg?branch=master" alt="Build Status" />](https://travis-ci.org/arekf/has_sti) [<img src="https://codeclimate.com/github/arekf/has_sti/badges/gpa.svg" />](https://codeclimate.com/github/arekf/has_sti) [<img src="https://codeclimate.com/github/arekf/has_sti/badges/coverage.svg" />](https://codeclimate.com/github/arekf/has_sti) [<img src="https://badge.fury.io/rb/has_sti.svg" alt="Gem Version" />](http://badge.fury.io/rb/has_sti)
2
+
3
+ # has_sti
4
+
5
+ `has_sti` is an ActiveRecord extension that provides helper methods and scopes
6
+ for STI models.
7
+
8
+ ## Installation
9
+ * Add `has_sti` to your Gemfile:
10
+ ```ruby
11
+ gem 'has_sti'
12
+ ```
13
+
14
+ * Install with: bundle install
15
+
16
+
17
+ ## Usage
18
+ We will use Ruby on Rails for this scenario. Let's say `User` model is a
19
+ parent STI class and you want to create child classes: `Admin` and `Reader`.
20
+ You start with defining STI as follows:
21
+
22
+ ```ruby
23
+ class User < ActiveRecord::Base
24
+ end
25
+
26
+ class Admin < User
27
+ end
28
+
29
+ class Reader < User
30
+ end
31
+ ```
32
+
33
+ Next step is creating migration for the database:
34
+ rails generate migration AddTypeToUser type:string
35
+
36
+ Then, we need to migrate database:
37
+ bundle exec rake db:migrate
38
+
39
+ Basic setup of STI is done. Here's where `has_sti` takes action.
40
+
41
+ Modify your `User` model to include `has_sti`:
42
+
43
+ ```ruby
44
+ class User < ActiveRecord::Base
45
+ has_sti :admin, :reader
46
+ end
47
+ ```
48
+
49
+ And that's it. Now you have following methods and scopes available:
50
+ ```ruby
51
+ some_admin = Admin.create
52
+
53
+ some_admin.admin? => true
54
+ some_admin.reader? => false
55
+
56
+ User.admin => [some_admin]
57
+ User.reader => []
58
+ ```
59
+
60
+ You can also disable helper methods:
61
+ ```ruby
62
+ class User < ActiveRecord::Base
63
+ has_sti :admin, :reader, helper_methods: false
64
+ end
65
+ ```
66
+
67
+ or scopes:
68
+ ```ruby
69
+ class User < ActiveRecord::Base
70
+ has_sti :admin, :reader, scopes: false
71
+ end
72
+ ```
73
+
74
+ or even set it per child class:
75
+ ```ruby
76
+ class User < ActiveRecord::Base
77
+ has_sti :admin, scopes: false
78
+ has_sti :reader, helper_methods: false
79
+ end
80
+ ```
81
+
82
+ No configuration is required. Custom STI column name is supported.
83
+
84
+ ## License
85
+ `has_sti` is released under the MIT license:
86
+ * http://www.opensource.org/licenses/MIT
87
+
88
+
89
+ ## Author
90
+ Arkadiusz Fal
91
+ * http://arekf.net
92
+
93
+
94
+ Copyright © 2015
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
10
10
  rdoc.rdoc_dir = 'rdoc'
11
11
  rdoc.title = 'HasSti'
12
12
  rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
13
+ rdoc.rdoc_files.include('README.md')
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
@@ -1,3 +1,3 @@
1
1
  module HasSti
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_sti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkadiusz Fal
@@ -90,7 +90,7 @@ extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
92
  - MIT-LICENSE
93
- - README.rdoc
93
+ - README.md
94
94
  - Rakefile
95
95
  - lib/has_sti.rb
96
96
  - lib/has_sti/active_record_extensions.rb
data/README.rdoc DELETED
@@ -1,74 +0,0 @@
1
- {<img src="https://travis-ci.org/arekf/has_sti.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/arekf/has_sti] {<img src="https://codeclimate.com/github/arekf/has_sti/badges/gpa.svg" />}[https://codeclimate.com/github/arekf/has_sti] {<img src="https://codeclimate.com/github/arekf/has_sti/badges/coverage.svg" />}[https://codeclimate.com/github/arekf/has_sti] {<img src="https://badge.fury.io/rb/has_sti.svg" alt="Gem Version" />}[http://badge.fury.io/rb/has_sti]
2
-
3
- = has_sti
4
-
5
- +has_sti+ is an ActiveRecord extension that provides helper methods and scopes for STI models.
6
-
7
- == Installation
8
- * Add +has_sti+ to your Gemfile:
9
- gem 'has_sti'
10
- * Install with:
11
- bundle install
12
-
13
- == Usage
14
- We will use Ruby on Rails for this scenario. Let's say +User+ model is a parent STI class and you want to create child classes: +Admin+ and +Reader+. You start with defining STI as follows:
15
-
16
- class User < ActiveRecord::Base
17
- end
18
-
19
- class Admin < User
20
- end
21
-
22
- class Reader < User
23
- end
24
-
25
- Next step is creating migration for the database:
26
- rails generate migration AddTypeToUser type:string
27
-
28
- Then, we need to migrate database:
29
- bundle exec rake db:migrate
30
-
31
- Basic setup of STI is done. Here's where +has_sti+ takes action.
32
-
33
- Modify your +User+ model to include +has_sti+:
34
-
35
- class User < ActiveRecord::Base
36
- has_sti :admin, :reader
37
- end
38
-
39
- And that's it. Now you have following methods and scopes available:
40
- some_admin = Admin.create
41
-
42
- some_admin.admin? => true
43
- some_admin.reader? => false
44
-
45
- User.admin => [some_admin]
46
- User.reader => []
47
-
48
- You can also disable helper methods:
49
- class User < ActiveRecord::Base
50
- has_sti :admin, :reader, helper_methods: false
51
- end
52
-
53
- or scopes:
54
- class User < ActiveRecord::Base
55
- has_sti :admin, :reader, scopes: false
56
- end
57
-
58
- or even set it per child class:
59
- class User < ActiveRecord::Base
60
- has_sti :admin, scopes: false
61
- has_sti :reader, helper_methods: false
62
- end
63
-
64
- No configuration is required. Custom STI column name is supported.
65
-
66
- == License
67
- +has_sti+ is released under the MIT license:
68
- * http://www.opensource.org/licenses/MIT
69
-
70
- == Author
71
- Arkadiusz Fal
72
- * http://arekf.net
73
-
74
- Copyright © 2015