activemodel_flags 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +148 -0
- data/Rakefile +2 -0
- data/activemodel_flags.gemspec +39 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/activemodel_flags/has_flags.rb +164 -0
- data/lib/activemodel_flags/version.rb +3 -0
- data/lib/activemodel_flags.rb +7 -0
- data/lib/generators/activemodel_flags/column_generator.rb +35 -0
- data/lib/generators/activemodel_flags/templates/migration.rb +14 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 46ac7c35b1859370a64e3739384db40216cc9321
|
4
|
+
data.tar.gz: 2905520aecf6cbc6164b9b50f8259b11961de6ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06edeb6d64b39ea2ea1a0deeb6c4edce6a8058d93a1f9ce0c898c7f4ba11fe821b6f3681eee3eda03c6a90daed8715e0a9502e94f42171efacdcb6d6bf1bc1f9
|
7
|
+
data.tar.gz: 72ad59696fa3f852cb206f2b0dd06fbf1fabeef1e98e13ed64e16c8fa7381ffd45c211b04b2379b92dad2f5bfbc99d5a3afcbc742b51330bc6c284d5e98f4b34
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at najibkaake@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Jay El-Kaake
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
![](http://i.imgur.com/jDIg5Xi.png)
|
2
|
+
# Active Model Flags Gem
|
3
|
+
![Travis build for User Timezone Gem](https://travis-ci.org/jayelkaake/activemodel_flags.svg?branch=master)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/activemodel_flags.svg)](https://badge.fury.io/rb/activemodel_flags)
|
5
|
+
The Active Model Flags Gem lets you attach the `has_flags` trait to your User, Account, or any other rails active models.
|
6
|
+
|
7
|
+
## Why would you need a flags attribute and this gem?
|
8
|
+
For some applications you don't want ot add a million different attributes in your database for flags that are potentially one-time events. For example, if you wanted to track whether a user has been notified of something, or has been sent an email. These arbitrary flag columns start to clutter your DB.
|
9
|
+
|
10
|
+
The Active Model Flags gem solves this issue by allowing you to arbitrarily set and get flags from a serialized column.
|
11
|
+
|
12
|
+
**Table of Contents**
|
13
|
+
* [Installation](#installation)
|
14
|
+
* [Usage](#usage)
|
15
|
+
* [Customization](#customization)
|
16
|
+
* [Other Things](#Other_Things)
|
17
|
+
|
18
|
+
# Installation
|
19
|
+
#### 1. Install the gem
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
```ruby
|
22
|
+
gem 'activemodel_flags'
|
23
|
+
```
|
24
|
+
And then execute:
|
25
|
+
$ bundle
|
26
|
+
Or install it yourself as:
|
27
|
+
$ gem install activemodel_flags
|
28
|
+
|
29
|
+
#### 2. Add 'has_flags' to your model
|
30
|
+
Choose the model you want to have flags and add the `has_flags` function to it. For example, with a User model this may look like this:
|
31
|
+
```ruby
|
32
|
+
class User < ActiveRecord::Base
|
33
|
+
# ...
|
34
|
+
has_flags
|
35
|
+
# ...
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
#### 3. Run the migration to add the DB column
|
40
|
+
Then, you'll need to install the column in your database. This gem comes with this generator for you that you can use like this:
|
41
|
+
```bash
|
42
|
+
rails g activemodel_flags:column User
|
43
|
+
rake db:migrate
|
44
|
+
```
|
45
|
+
Replace `User` with your own model class.
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
# Usage
|
51
|
+
|
52
|
+
## Setters
|
53
|
+
Once a model has_flags then you can now set a flag like this:
|
54
|
+
```ruby
|
55
|
+
user = User.create
|
56
|
+
|
57
|
+
user.has! :been_sent_email_about_usage
|
58
|
+
|
59
|
+
user.has? :been_sent_email_about_usage
|
60
|
+
# false
|
61
|
+
```
|
62
|
+
or you can do the opposite:
|
63
|
+
```ruby
|
64
|
+
user = User.create
|
65
|
+
|
66
|
+
user.hasnt! :been_sent_email_about_usage
|
67
|
+
|
68
|
+
user.has? :been_sent_email_about_usage
|
69
|
+
# true
|
70
|
+
```
|
71
|
+
|
72
|
+
To set the value without saving to the DB use `user.has :been_sent_email_about_usage`.
|
73
|
+
|
74
|
+
## Getters
|
75
|
+
Consider this example to see how the getters work:
|
76
|
+
```ruby
|
77
|
+
user = User.create
|
78
|
+
|
79
|
+
user.has! :been_sent_email_about_usage
|
80
|
+
|
81
|
+
user.has? :been_sent_email_about_usage
|
82
|
+
# true
|
83
|
+
|
84
|
+
user.hasnt? :been_sent_email_about_usage
|
85
|
+
# false
|
86
|
+
|
87
|
+
user.has? :been_eating_a_big_chocolate_cake
|
88
|
+
# false
|
89
|
+
```
|
90
|
+
|
91
|
+
## Querying
|
92
|
+
Generally this gem is not made for mass querying, so if you plan on doing joins based on the flag attribute then this gem is probably to for you and you should use a boolean column.
|
93
|
+
|
94
|
+
### Get models that have or don't have the flag set
|
95
|
+
That being said, here's how you can use the
|
96
|
+
```ruby
|
97
|
+
User.that_havent?(:been_sent_email_about_usage) do |user|
|
98
|
+
# * send that user the email about usage here. *
|
99
|
+
user.has! :been_sent_email_about_usage
|
100
|
+
end
|
101
|
+
# Returns query list of all users that have been sent a message
|
102
|
+
```
|
103
|
+
|
104
|
+
### Get all avaialble flags
|
105
|
+
If you want to now what flags are being used for **debugging purposes** then you can use
|
106
|
+
```ruby
|
107
|
+
u = User.flags_used
|
108
|
+
# returns something like ["been_sent_email_about_usage", "been_eating_a_big_chocolate_cake"]
|
109
|
+
```
|
110
|
+
|
111
|
+
### Set the flags for a group of users
|
112
|
+
```ruby
|
113
|
+
User.where("age > ?", 40).all_have! :seen_james_bond_movies
|
114
|
+
# Sets the seen_james_bond_movies flag to true for all matched users.
|
115
|
+
```
|
116
|
+
And to do the opposite (set the flag to false for all matched users):
|
117
|
+
```ruby
|
118
|
+
User.that_have?(:used_a_cd).where("age < ", 20).all_have_not! :felt_the_anger_of_skipping_cds
|
119
|
+
# Sets the felt_the_anger_of_skipping_cds flag to false for all matched users
|
120
|
+
```
|
121
|
+
|
122
|
+
### Reset a particular flag for some users
|
123
|
+
```ruby
|
124
|
+
User.where(took_the_red_pill: true).reset_flags! :been_in_the_matrix
|
125
|
+
# Now all users that were matched will return false for has?(:been_in_the_matrix)
|
126
|
+
```
|
127
|
+
|
128
|
+
### Nuke (reset) all flags
|
129
|
+
```ruby
|
130
|
+
User.reset_all_flags!
|
131
|
+
```
|
132
|
+
|
133
|
+
# Customization
|
134
|
+
Models that have the has_flags trait will call the protected method `on_flag_change(old_val, new_val)` any time the value of their flag changes, but only if it is done individually.
|
135
|
+
|
136
|
+
Feel free to fork and contribute so we can make this better!
|
137
|
+
|
138
|
+
# Other Things
|
139
|
+
### Roadmap
|
140
|
+
* Build in method_missing functionality so you can do things like `model.has_eaten_a_pie!` and `model.has_eaten_a_pie?`
|
141
|
+
* Make the flags column customizable so you can add multiple flag columns
|
142
|
+
### Contributing
|
143
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jayelkaake/user_timezone.
|
144
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to
|
145
|
+
adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
146
|
+
|
147
|
+
### License
|
148
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activemodel_flags/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "activemodel_flags"
|
8
|
+
spec.version = ActivemodelFlags::VERSION
|
9
|
+
spec.authors = ["Jay El-Kaake"]
|
10
|
+
spec.email = ["najibkaake@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Adds beautifully readable true/false flags to user and account active models (like devise).}
|
13
|
+
spec.description = %q{This gem adds the ability for models to have an unlimited number of custom flags \
|
14
|
+
that are stored within one database column cell instead of several columns.}
|
15
|
+
spec.homepage = "https://www.github.com/jayelkaake/activemodel_flags"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
19
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
20
|
+
# if spec.respond_to?(:metadata)
|
21
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
22
|
+
# else
|
23
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "rails", ">= 4.0.0"
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", ">= 1.10"
|
34
|
+
spec.add_development_dependency "temping", "~> 3.3.0"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", '~> 3.4'
|
37
|
+
spec.add_development_dependency "sqlite3"
|
38
|
+
|
39
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "activemodel_flags"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
module ActivemodelFlags
|
3
|
+
module HasFlags
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
|
8
|
+
##
|
9
|
+
# This will add the ability for the model to set and read flags.
|
10
|
+
# @note: The model must have the 'flags' column. Use rails g activemodel_flags:column *model_name* to generate the migration for the flags column
|
11
|
+
#
|
12
|
+
def has_flags
|
13
|
+
include LocalInstanceMethods
|
14
|
+
|
15
|
+
before_create :init_flags
|
16
|
+
after_initialize :init_flags
|
17
|
+
serialize :flags, JSON
|
18
|
+
|
19
|
+
scope :that_have?, -> (key) {
|
20
|
+
where("flags LIKE '%\"#{key}\":true%'")
|
21
|
+
}
|
22
|
+
scope :that_havent?, -> (key) {
|
23
|
+
where("flags NOT LIKE '%\"#{key}\":true%'")
|
24
|
+
}
|
25
|
+
scope :that_have_not?, -> (key) { that_havent?(key) }
|
26
|
+
|
27
|
+
scope :that_have_any_flags, -> {
|
28
|
+
where("flags != '{}' AND flags IS NOT NULL")
|
29
|
+
}
|
30
|
+
|
31
|
+
scope :all_have!, -> (flag) {
|
32
|
+
self.reset_flags!(flag)
|
33
|
+
self.update_all("flags = REPLACE(flags, '}', '\"#{flag}\":true}')")
|
34
|
+
}
|
35
|
+
scope :all_have_not!, -> (flag) {
|
36
|
+
self.reset_flags!(flag)
|
37
|
+
self.update_all("flags = REPLACE(flags, '}', '\"#{flag}\":false}')")
|
38
|
+
}
|
39
|
+
|
40
|
+
def self.flags_used
|
41
|
+
all_flags = {}
|
42
|
+
|
43
|
+
self.that_have_any_flags.each do |obj|
|
44
|
+
obj.flags.keys.each do |key|
|
45
|
+
all_flags[key] = true unless all_flags[key]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
all_flags.keys
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.reset_flags!(flag)
|
53
|
+
self.update_all("flags = REPLACE(\
|
54
|
+
REPLACE(\
|
55
|
+
REPLACE(\
|
56
|
+
REPLACE(
|
57
|
+
flags, '\"#{flag}\":false', ''\
|
58
|
+
), '\"#{flag}\":false,', ''\
|
59
|
+
), '\"#{flag}\":true,', ''\
|
60
|
+
), '\"#{flag}\":true', ''\
|
61
|
+
)")
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.reset_all_flags!
|
65
|
+
self.update_all(flags: '{}')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module LocalInstanceMethods
|
71
|
+
|
72
|
+
#### getters
|
73
|
+
def has_flag?(flag)
|
74
|
+
self.flags[flag.to_s] != nil
|
75
|
+
end
|
76
|
+
def has?(flag)
|
77
|
+
self.flags[flag.to_s]
|
78
|
+
end
|
79
|
+
|
80
|
+
def hasnt?(flag)
|
81
|
+
!has?(flag)
|
82
|
+
end
|
83
|
+
alias_method :has_not?, :hasnt?
|
84
|
+
|
85
|
+
|
86
|
+
#### setters
|
87
|
+
|
88
|
+
def has(flag)
|
89
|
+
old_flags = self.flags
|
90
|
+
|
91
|
+
self.flags[flag.to_s] = true
|
92
|
+
|
93
|
+
on_flag_change(old_flags[flag.to_s], self.flags[flag.to_s]) unless old_flags == self.flags
|
94
|
+
end
|
95
|
+
|
96
|
+
def has!(flag)
|
97
|
+
has(flag)
|
98
|
+
|
99
|
+
self.save!
|
100
|
+
end
|
101
|
+
|
102
|
+
def hasnt!(flag)
|
103
|
+
old_flags = self.flags
|
104
|
+
|
105
|
+
self.flags[flag.to_s] = false
|
106
|
+
|
107
|
+
on_flag_change(old_flags[flag.to_s], self.flags[flag.to_s]) unless old_flags == self.flags
|
108
|
+
self.save!
|
109
|
+
end
|
110
|
+
alias_method :has_not!, :hasnt!
|
111
|
+
|
112
|
+
def unset_flag!(flag)
|
113
|
+
old_flags = self.flags
|
114
|
+
|
115
|
+
self.flags.delete(flag.to_s)
|
116
|
+
|
117
|
+
on_flag_change(old_flags[flag.to_s], self.flags[flag.to_s]) unless old_flags == self.flags
|
118
|
+
self.save!
|
119
|
+
end
|
120
|
+
|
121
|
+
# TODO implement the ability to
|
122
|
+
# def method_missing(method)
|
123
|
+
# if method.to_s =~ /has_[a-zA-Z0-9_]+\?/
|
124
|
+
# key = method.to_s.chomp("?").reverse.chomp("_sah").reverse
|
125
|
+
# has = true
|
126
|
+
# elsif method.to_s =~ /hasnt_[a-zA-Z0-9_]+\?/
|
127
|
+
# key = method.to_s.chomp("?").reverse.chomp("_tnsah").reverse
|
128
|
+
# has = false
|
129
|
+
# elsif method.to_s =~ /has_not_[a-zA-Z0-9_]+\?/
|
130
|
+
# key = method.to_s.chomp("?").reverse.chomp("_ton_sah").reverse
|
131
|
+
# has = false
|
132
|
+
# else
|
133
|
+
# return super
|
134
|
+
# end
|
135
|
+
#
|
136
|
+
# if has_flag?(method.to_s)
|
137
|
+
# has ? has?(key) : hasnt?(key)
|
138
|
+
# else
|
139
|
+
# puts "*************** NO METHOD!! "
|
140
|
+
# super
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
|
144
|
+
def respond_to?(method)
|
145
|
+
has_flag?(method.to_s) || super(method)
|
146
|
+
end
|
147
|
+
|
148
|
+
protected
|
149
|
+
|
150
|
+
def on_flag_change(old_val, new_val)
|
151
|
+
# Override this method if you want to react to flag changes
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def init_flags
|
157
|
+
self.flags = {} unless self.flags.present?
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
ActiveRecord::Base.send :include, ActivemodelFlags::HasFlags
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module ActivemodelFlags
|
2
|
+
class ColumnGenerator < Rails::Generators::NamedBase
|
3
|
+
include Rails::Generators::Migration
|
4
|
+
desc "Generates the migration to add a flags column to a rails model."
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def manifest
|
8
|
+
migration_template 'migration.rb', "db/migrate/add_flags_to_#{custom_file_name}.rb", {
|
9
|
+
:assigns => flags_local_assigns,
|
10
|
+
:migration_file_name => "add_flags_field_to_#{custom_file_name}"
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.next_migration_number(dir)
|
15
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def custom_file_name
|
21
|
+
custom_name = class_name.underscore.downcase
|
22
|
+
custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
|
23
|
+
custom_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def flags_local_assigns
|
27
|
+
{}.tap do |assigns|
|
28
|
+
assigns[:migration_action] = "add"
|
29
|
+
assigns[:class_name] = "add_flags_fields_to_#{custom_file_name}"
|
30
|
+
assigns[:table_name] = custom_file_name
|
31
|
+
assigns[:attributes] = [Rails::Generators::GeneratedAttribute.new("flags", "text")]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class AddFlagsTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def up
|
4
|
+
add_column :<%= table_name %>, :flags, :text
|
5
|
+
|
6
|
+
<%= class_name.camelize.singularize %>.all.each do |obj|
|
7
|
+
obj.update!(flags: {})
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
remove_column :<%= table_name %>, :flags
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activemodel_flags
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jay El-Kaake
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: temping
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: |-
|
98
|
+
This gem adds the ability for models to have an unlimited number of custom flags \
|
99
|
+
that are stored within one database column cell instead of several columns.
|
100
|
+
email:
|
101
|
+
- najibkaake@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- activemodel_flags.gemspec
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- lib/activemodel_flags.rb
|
116
|
+
- lib/activemodel_flags/has_flags.rb
|
117
|
+
- lib/activemodel_flags/version.rb
|
118
|
+
- lib/generators/activemodel_flags/column_generator.rb
|
119
|
+
- lib/generators/activemodel_flags/templates/migration.rb
|
120
|
+
homepage: https://www.github.com/jayelkaake/activemodel_flags
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.4.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Adds beautifully readable true/false flags to user and account active models
|
144
|
+
(like devise).
|
145
|
+
test_files: []
|
146
|
+
has_rdoc:
|