acts_as_resource 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 +11 -0
- data/.pryrc +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +6 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +86 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/Rakefile +6 -0
- data/acts_as_resource.gemspec +31 -0
- data/bin/console +31 -0
- data/bin/setup +8 -0
- data/lib/acts_as_resource.rb +16 -0
- data/lib/acts_as_resource/accessable.rb +13 -0
- data/lib/acts_as_resource/base.rb +37 -0
- data/lib/acts_as_resource/resourceable.rb +13 -0
- data/lib/acts_as_resource/resourceship.rb +10 -0
- data/lib/acts_as_resource/version.rb +3 -0
- data/lib/generators/acts_as_resource/migration/migration_generator.rb +23 -0
- data/lib/generators/acts_as_resource/migration/templates/migration.rb +28 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f0606da00302cf19907da8faa8088b7360e6c5f6de02b4d45d5df185dd18fe95
|
4
|
+
data.tar.gz: e468f6b5d1d11b1966e4e8199694f3c7be83278047b45ace8b6f8a1cb0111ebd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c998a21e5a34c34ee6b5bed09aa9712768d215b9fa039a4556930b3b02bc6b708ef4afbc964556eb5c2054b718ad4790dd78a482d0e1c0ca68322bdecc7e6f95
|
7
|
+
data.tar.gz: 26536cae50fcf886280d2d07e6a93ab2399cf7a8a8d4805644ad23b949ab235a54e4d39248813ddb6ed901d49226a6e790bb786daac5ca09bad0bdc99cfe26d9
|
data/.gitignore
ADDED
data/.pryrc
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
if defined?(PryByebug)
|
2
|
+
Pry.commands.alias_command 'c', 'continue'
|
3
|
+
Pry.commands.alias_command 's', 'step'
|
4
|
+
Pry.commands.alias_command 'n', 'next'
|
5
|
+
Pry.commands.alias_command 'f', 'finish'
|
6
|
+
|
7
|
+
# Hit Enter to repeat last command
|
8
|
+
Pry::Commands.command(/^$/, 'repeat last command') do
|
9
|
+
_pry_.run_command Pry.history.to_a.last
|
10
|
+
end
|
11
|
+
end
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at darren987469@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
acts_as_resource (0.1.0)
|
5
|
+
activerecord
|
6
|
+
activesupport
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.2.0)
|
12
|
+
activesupport (= 5.2.0)
|
13
|
+
activerecord (5.2.0)
|
14
|
+
activemodel (= 5.2.0)
|
15
|
+
activesupport (= 5.2.0)
|
16
|
+
arel (>= 9.0)
|
17
|
+
activesupport (5.2.0)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 0.7, < 2)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (9.0.0)
|
23
|
+
byebug (10.0.2)
|
24
|
+
coderay (1.1.2)
|
25
|
+
concurrent-ruby (1.0.5)
|
26
|
+
coveralls (0.8.21)
|
27
|
+
json (>= 1.8, < 3)
|
28
|
+
simplecov (~> 0.14.1)
|
29
|
+
term-ansicolor (~> 1.3)
|
30
|
+
thor (~> 0.19.4)
|
31
|
+
tins (~> 1.6)
|
32
|
+
diff-lcs (1.3)
|
33
|
+
docile (1.1.5)
|
34
|
+
i18n (1.0.1)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
json (2.1.0)
|
37
|
+
method_source (0.9.0)
|
38
|
+
minitest (5.11.3)
|
39
|
+
pry (0.11.3)
|
40
|
+
coderay (~> 1.1.0)
|
41
|
+
method_source (~> 0.9.0)
|
42
|
+
pry-byebug (3.6.0)
|
43
|
+
byebug (~> 10.0)
|
44
|
+
pry (~> 0.10)
|
45
|
+
rake (12.3.1)
|
46
|
+
rspec (3.7.0)
|
47
|
+
rspec-core (~> 3.7.0)
|
48
|
+
rspec-expectations (~> 3.7.0)
|
49
|
+
rspec-mocks (~> 3.7.0)
|
50
|
+
rspec-core (3.7.1)
|
51
|
+
rspec-support (~> 3.7.0)
|
52
|
+
rspec-expectations (3.7.0)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.7.0)
|
55
|
+
rspec-mocks (3.7.0)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.7.0)
|
58
|
+
rspec-support (3.7.1)
|
59
|
+
simplecov (0.14.1)
|
60
|
+
docile (~> 1.1.0)
|
61
|
+
json (>= 1.8, < 3)
|
62
|
+
simplecov-html (~> 0.10.0)
|
63
|
+
simplecov-html (0.10.2)
|
64
|
+
sqlite3 (1.3.13)
|
65
|
+
term-ansicolor (1.6.0)
|
66
|
+
tins (~> 1.0)
|
67
|
+
thor (0.19.4)
|
68
|
+
thread_safe (0.3.6)
|
69
|
+
tins (1.16.3)
|
70
|
+
tzinfo (1.2.5)
|
71
|
+
thread_safe (~> 0.1)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
ruby
|
75
|
+
|
76
|
+
DEPENDENCIES
|
77
|
+
acts_as_resource!
|
78
|
+
bundler
|
79
|
+
coveralls
|
80
|
+
pry-byebug
|
81
|
+
rake
|
82
|
+
rspec
|
83
|
+
sqlite3
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 darren.chang
|
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,88 @@
|
|
1
|
+
# ActsAsResource
|
2
|
+
[![Build Status](https://travis-ci.org/darren987469/acts_as_resource.svg?branch=master)](https://travis-ci.org/darren987469/acts_as_resource)
|
3
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/69fe56be3a4113d0ac57/maintainability)](https://codeclimate.com/github/darren987469/acts_as_resource/maintainability)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/darren987469/acts_as_resource/badge.svg?branch=master)](https://coveralls.io/github/darren987469/resource?branch=master)
|
5
|
+
|
6
|
+
This gem handle whether user can access the resources. Resource cab be project, document, etc.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'acts_as_resource'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Generate migration and run it
|
21
|
+
|
22
|
+
```shell
|
23
|
+
rails g acts_as_resource:migration
|
24
|
+
rake db:migrate
|
25
|
+
```
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class User < ActiveRecord::Base
|
31
|
+
acts_as_accessable resources: [ :projects ]
|
32
|
+
# resources option help to define has_many :projects
|
33
|
+
# resources option is optional
|
34
|
+
end
|
35
|
+
|
36
|
+
class Project < ActiveRecord::Base
|
37
|
+
acts_as_resource accessors: [ :users ]
|
38
|
+
# accessors option help to define has_many :users association
|
39
|
+
# accessors option is optional
|
40
|
+
end
|
41
|
+
|
42
|
+
user = User.create!
|
43
|
+
project = Project.create!
|
44
|
+
|
45
|
+
user.projects
|
46
|
+
# => [ ]
|
47
|
+
project.users
|
48
|
+
# => [ ]
|
49
|
+
user.can_access?(project)
|
50
|
+
# => false
|
51
|
+
project.accessible_by?(user)
|
52
|
+
# => false
|
53
|
+
|
54
|
+
user.projects << project # or project.users << user
|
55
|
+
user.projects
|
56
|
+
# => [ project ]
|
57
|
+
project.users
|
58
|
+
# => [ user ]
|
59
|
+
user.can_access?(project)
|
60
|
+
# => true
|
61
|
+
project.accessible_by?(user)
|
62
|
+
# => true
|
63
|
+
|
64
|
+
another_user = User.create!
|
65
|
+
another_user.can_access?(project)
|
66
|
+
# => false
|
67
|
+
```
|
68
|
+
|
69
|
+
## How it works?
|
70
|
+
In install step, migration will create [`resourceships`](https://github.com/darren987469/acts_as_resource/blob/master/lib/acts_as_resource/resourceship.rb) table. This table help to store accessors and resources' relation.
|
71
|
+
|
72
|
+
## Development
|
73
|
+
|
74
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
75
|
+
|
76
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/darren987469/acts_as_resource. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
85
|
+
|
86
|
+
## Code of Conduct
|
87
|
+
|
88
|
+
Everyone interacting in the Resource project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/darren987469/acts_as_resource/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'acts_as_resource/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'acts_as_resource'
|
7
|
+
spec.version = ActsAsResource::VERSION
|
8
|
+
spec.authors = ['darren.chang']
|
9
|
+
spec.email = ['darren987469@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'User resource management gem.'
|
12
|
+
spec.homepage = 'https://github.com/darren987469/acts_as_resource'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'activerecord'
|
23
|
+
spec.add_dependency 'activesupport'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'coveralls'
|
27
|
+
spec.add_development_dependency 'pry-byebug'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'rspec'
|
30
|
+
spec.add_development_dependency 'sqlite3'
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'acts_as_resource'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.expand_path('..', File.dirname(__FILE__)))
|
7
|
+
require 'lib/generators/acts_as_resource/migration/templates/migration.rb'
|
8
|
+
require 'spec/support/spec_migration.rb'
|
9
|
+
|
10
|
+
require 'spec/app/models/user'
|
11
|
+
require 'spec/app/models/project'
|
12
|
+
|
13
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
14
|
+
# with your gem easier. You can also use a different console, if you like.
|
15
|
+
|
16
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
17
|
+
# require "pry"
|
18
|
+
# Pry.start
|
19
|
+
|
20
|
+
db_config = YAML.load_file('spec/database.yml').fetch(ENV['DB'] || 'sqlite')
|
21
|
+
ActiveRecord::Base.establish_connection(db_config)
|
22
|
+
ActiveRecord::Schema.verbose = false
|
23
|
+
|
24
|
+
ActsAsResourceMigration.up
|
25
|
+
SpecMigration.up
|
26
|
+
|
27
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT) if defined?(Logger)
|
28
|
+
ActiveRecord::Base.connection.schema_cache.clear!
|
29
|
+
|
30
|
+
require 'irb'
|
31
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
require 'acts_as_resource/accessable'
|
4
|
+
require 'acts_as_resource/resourceable'
|
5
|
+
require 'acts_as_resource/resourceship'
|
6
|
+
require 'acts_as_resource/base'
|
7
|
+
require 'acts_as_resource/version'
|
8
|
+
|
9
|
+
ActiveRecord::Base.send :include, ActsAsResource
|
10
|
+
|
11
|
+
ActsAsResource::MIGRATION_BASE_CLASS =
|
12
|
+
if ActiveRecord::VERSION::MAJOR >= 5
|
13
|
+
ActiveRecord::Migration[5.0]
|
14
|
+
else
|
15
|
+
ActiveRecord::Migration
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActsAsResource
|
2
|
+
module Accessable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :resourceships, as: :accessable, dependent: :delete_all
|
7
|
+
|
8
|
+
def can_access?(resource)
|
9
|
+
resourceships.where(resourceable: resource).exists?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActsAsResource
|
2
|
+
def self.included(base)
|
3
|
+
base.extend Base
|
4
|
+
end
|
5
|
+
|
6
|
+
module Base
|
7
|
+
def acts_as_accessable(options = {})
|
8
|
+
return if Resourceship.accessable_classes.include?(self)
|
9
|
+
|
10
|
+
include ActsAsResource::Accessable
|
11
|
+
|
12
|
+
return unless options[:resources]
|
13
|
+
|
14
|
+
options[:resources].each do |resource|
|
15
|
+
has_many resource,
|
16
|
+
through: :resourceships,
|
17
|
+
source: :resourceable,
|
18
|
+
source_type: resource.to_s.singularize.classify
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def acts_as_resource(options = {})
|
23
|
+
return if Resourceship.resourceable_classes.include?(self)
|
24
|
+
|
25
|
+
include ActsAsResource::Resourceable
|
26
|
+
|
27
|
+
return unless options[:accessors]
|
28
|
+
|
29
|
+
options[:accessors].each do |accessor|
|
30
|
+
has_many accessor,
|
31
|
+
through: :resourceships,
|
32
|
+
source: :accessable,
|
33
|
+
source_type: accessor.to_s.singularize.classify
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActsAsResource
|
2
|
+
module Resourceable
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
has_many :resourceships, as: :resourceable, dependent: :delete_all
|
7
|
+
|
8
|
+
def accessible_by?(accessable)
|
9
|
+
resourceships.where(accessable: accessable).exists?
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Resourceship < ActiveRecord::Base
|
2
|
+
class_attribute :accessable_classes
|
3
|
+
class_attribute :resourceable_classes
|
4
|
+
|
5
|
+
self.accessable_classes = []
|
6
|
+
self.resourceable_classes = []
|
7
|
+
|
8
|
+
belongs_to :accessable, polymorphic: true
|
9
|
+
belongs_to :resourceable, polymorphic: true
|
10
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module ActsAsResource
|
5
|
+
class MigrationGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
desc 'Generates migration for acts_as_resource'
|
9
|
+
source_root File.expand_Path('../templates', __FILE__)
|
10
|
+
|
11
|
+
def create_migration_file
|
12
|
+
migration_template 'migration.rb', 'db/migrate/acts_as_resource_migration.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.next_migration_number(dirname)
|
16
|
+
if ActiveRecord::Base.timestamped_migrations
|
17
|
+
Time.now.utc.strftime('%Y%m%d%H%M%S')
|
18
|
+
else
|
19
|
+
format('%.3d', (current_migration_number(dirname) + 1))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class ActsAsResourceMigration < ActsAsResource::MIGRATION_BASE_CLASS
|
2
|
+
def self.up
|
3
|
+
create_table Resourceship, force: true, options: create_options do |t|
|
4
|
+
t.references :accessable, polymorphic: { null: false }
|
5
|
+
t.references :resourceable, polymorphic: { null: false }
|
6
|
+
end
|
7
|
+
|
8
|
+
add_index(
|
9
|
+
Resourceship,
|
10
|
+
%i[accessable_id accessable_type resourceable_id resourceable_type],
|
11
|
+
name: 'relationships_accesable_resourceable_index',
|
12
|
+
unique: true
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.down
|
17
|
+
drop_table Resourceship
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.create_options
|
21
|
+
options = ''
|
22
|
+
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) \
|
23
|
+
&& ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
|
24
|
+
options = 'DEFAULT CHARSET=latin1'
|
25
|
+
end
|
26
|
+
options
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acts_as_resource
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- darren.chang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- darren987469@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".pryrc"
|
134
|
+
- ".rspec"
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".travis.yml"
|
137
|
+
- CODE_OF_CONDUCT.md
|
138
|
+
- Gemfile
|
139
|
+
- Gemfile.lock
|
140
|
+
- LICENSE.txt
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- acts_as_resource.gemspec
|
144
|
+
- bin/console
|
145
|
+
- bin/setup
|
146
|
+
- lib/acts_as_resource.rb
|
147
|
+
- lib/acts_as_resource/accessable.rb
|
148
|
+
- lib/acts_as_resource/base.rb
|
149
|
+
- lib/acts_as_resource/resourceable.rb
|
150
|
+
- lib/acts_as_resource/resourceship.rb
|
151
|
+
- lib/acts_as_resource/version.rb
|
152
|
+
- lib/generators/acts_as_resource/migration/migration_generator.rb
|
153
|
+
- lib/generators/acts_as_resource/migration/templates/migration.rb
|
154
|
+
homepage: https://github.com/darren987469/acts_as_resource
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
metadata: {}
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 2.7.6
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: User resource management gem.
|
178
|
+
test_files: []
|