Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
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
shotengai
Commits
09d97099
Commit
09d97099
authored
Jun 06, 2018
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add module Shotengai::JoinCatalog
parent
31df0e3c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
33 deletions
+48
-33
shotengai.rb
lib/shotengai.rb
+1
-0
join_catalog.rb
lib/shotengai/join_catalog.rb
+45
-0
product.rb
lib/shotengai/product.rb
+2
-33
No files found.
lib/shotengai.rb
View file @
09d97099
...
...
@@ -12,6 +12,7 @@ module Shotengai
autoload
:Catalog
,
'shotengai/catalog'
autoload
:AASM_DLC
,
'shotengai/aasm_dlc'
autoload
:WebError
,
'shotengai/web_error'
autoload
:JoinCatalog
,
'shotengai/join_catalog'
autoload
:JsonColumn
,
'shotengai/json_column'
autoload
:Harray
,
'shotengai/harray'
autoload
:Model
,
'shotengai/model'
...
...
lib/shotengai/join_catalog.rb
0 → 100644
View file @
09d97099
module
Shotengai
module
JoinCatalog
extend
ActiveSupport
::
Concern
included
do
require
'acts-as-taggable-on'
end
class_methods
do
def
join_catalog_system
catalog_class_name
,
options
=
{}
catalog_class
=
catalog_class_name
.
constantize
tag_name
=
options
[
:as
]
||
catalog_class
.
model_name
.
singular
acts_as_taggable_on
tag_name
.
to_sym
list_name
=
"
#{
tag_name
}
_list"
.
to_sym
class_eval
do
# define_method("#{tag_name}_list=") { |value|
# super catalog_class.validate_name_chain(value)
# }
scope
"
#{
list_name
}
_filter"
.
to_sym
,
->
(
catalogs
)
{
tags
=
catalogs
&&
catalogs
.
try
(
:tag
)
||
catalogs
.
any?
&&
catalogs
&
.
map
(
&
:tag
)
tags
?
tagged_with
(
tags
,
on:
list_name
)
:
all
}
define_method
(
"
#{
tag_name
}
_ids="
)
{
|
ids
|
send
(
"
#{
list_name
}
="
,
catalog_class
.
ids_to_tags
(
ids
))
}
define_method
(
"
#{
tag_name
}
_ids"
)
{
send
(
list_name
).
map
(
&
:id
)
}
define_method
(
"
#{
tag_name
}
_names"
)
{
send
(
list_name
).
map
(
&
:name
)
}
define_method
(
list_name
)
{
catalog_class
.
unscope
(
:order
).
where
(
id:
super
().
map
{
|
tag
|
Shotengai
::
Catalog
.
parse_tag
(
tag
)
}).
order
(
:nested_level
)
}
end
end
end
end
end
\ No newline at end of file
lib/shotengai/product.rb
View file @
09d97099
...
...
@@ -28,7 +28,6 @@ module Shotengai
#
class
Product
<
Shotengai
::
Model
require
'acts-as-taggable-on'
self
.
table_name
=
'shotengai_products'
harray_accessor
:spec_template
,
:remark_template
...
...
@@ -123,41 +122,11 @@ module Shotengai
subclass
.
has_many
:snapshots
,
class_name:
subclass
.
snapshot_class
.
name
,
through: :series
,
source: :snapshots
end
# Will get methods:
# "#{tag_name}_list" tag_name is singular
# tagger_with('xx', on: "#{tag_name}.to_sym): tag_name is plural
def
join_catalog_system
catalog_class_name
,
options
=
{}
catalog_class
=
catalog_class_name
.
constantize
tag_name
=
options
[
:as
]
||
catalog_class
.
model_name
.
singular
acts_as_taggable_on
tag_name
.
to_sym
list_name
=
"
#{
tag_name
}
_list"
.
to_sym
class_eval
do
# define_method("#{tag_name}_list=") { |value|
# super catalog_class.validate_name_chain(value)
# }
scope
"
#{
list_name
}
_filter"
.
to_sym
,
->
(
catalogs
)
{
tags
=
catalogs
&&
catalogs
.
try
(
:tag
)
||
catalogs
.
any?
&&
catalogs
&
.
map
(
&
:tag
)
tags
?
tagged_with
(
tags
,
on:
list_name
)
:
all
}
define_method
(
"
#{
tag_name
}
_ids="
)
{
|
ids
|
send
(
"
#{
list_name
}
="
,
catalog_class
.
ids_to_tags
(
ids
))
}
define_method
(
"
#{
tag_name
}
_ids"
)
{
send
(
list_name
).
map
(
&
:id
)
}
define_method
(
"
#{
tag_name
}
_names"
)
{
send
(
list_name
).
map
(
&
:name
)
}
define_method
(
list_name
)
{
catalog_class
.
unscope
(
:order
).
where
(
id:
super
().
map
{
|
tag
|
Shotengai
::
Catalog
.
parse_tag
(
tag
)
}).
order
(
:nested_level
)
}
end
end
include
JoinCatalog
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