Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
acts_as_pasting
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
acts_as_pasting
Commits
aa8811ee
Commit
aa8811ee
authored
Jun 27, 2020
by
Ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pasteable
parent
1aa69952
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
3 deletions
+40
-3
acts_as_pasting.rb
lib/acts_as_pasting.rb
+3
-2
pasteable.rb
lib/acts_as_pasting/pasteable.rb
+36
-0
pasting.rb
lib/acts_as_pasting/pasting.rb
+1
-1
No files found.
lib/acts_as_pasting.rb
View file @
aa8811ee
...
...
@@ -2,8 +2,9 @@ require "acts_as_pasting/version"
module
ActsAsPasting
require
'acts_as_pasting/errors'
autoload
:Pasted
,
'acts_as_pasting/pasted'
autoload
:Pasting
,
'acts_as_pasting/pasting'
autoload
:Pasted
,
'acts_as_pasting/pasted'
autoload
:Pasteable
,
'acts_as_pasting/pasteable'
autoload
:Pasting
,
'acts_as_pasting/pasting'
def
self
.
table_name_prefix
'acts_as_pasting_'
...
...
lib/acts_as_pasting/pasteable.rb
0 → 100644
View file @
aa8811ee
module
ActsAsPasting
module
Pasteable
extend
ActiveSupport
::
Concern
# 带 prefix 的 pasted_with,独立于不带 prefix 的之外
included
do
has_many
:pastings
,
as: :pasteable
,
class_name:
'ActsAsPasting::Pasting'
has_many
:hosts
,
through: :pastings
# ary => [[klass, id], [klass, id]]
# ary => [obj, obj]
scope
:pasted_with_any
,
->
(
ary
,
prefix:
''
)
{
ary
=
parsed_condition_ary
(
ary
)
ids
=
ary
.
map
do
|
klass
,
id
|
joins
(
:pastings
).
where
(
acts_as_pasting_pastings:
{
pasted_type:
klass
.
constantize
.
base_class
.
name
,
pasted_id:
id
,
type:
prefix
}).
pluck
(
:id
)
end
.
reduce
(
:|
)
where
(
id:
ids
)
}
scope
:pasted_with_all
,
->
(
ary
,
prefix:
''
)
{
ary
=
parsed_condition_ary
(
ary
)
ids
=
ary
.
map
do
|
klass
,
id
|
joins
(
:pastings
).
where
(
acts_as_pasting_pastings:
{
pasted_type:
klass
.
constantize
.
base_class
.
name
,
pasted_id:
id
,
type:
prefix
}).
pluck
(
:id
)
end
.
reduce
(
:&
)
where
(
id:
ids
)
}
end
module
ClassMethods
end
end
end
lib/acts_as_pasting/pasting.rb
View file @
aa8811ee
...
...
@@ -24,5 +24,5 @@ module ActsAsPasting
belongs_to
:pasteable
,
polymorphic:
true
belongs_to
:pasted
,
polymorphic:
true
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment