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
d28f79ad
Commit
d28f79ad
authored
Sep 12, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add require_custom_file to the inherited of Series & Snapshot
parent
fef8cd60
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
8 deletions
+21
-8
product.rb
lib/shotengai/product.rb
+1
-1
series.rb
lib/shotengai/series.rb
+13
-7
snapshot.rb
lib/shotengai/snapshot.rb
+7
-0
No files found.
lib/shotengai/product.rb
View file @
d28f79ad
...
...
@@ -82,7 +82,7 @@ module Shotengai
def
define_related_class
subclass
# Useing Class.new could not get class_name in self.inherited
class_eval
(
"
class ::
#{
subclass
}
Series <
#{
self
.
series_class
}
; end
;
class ::
#{
subclass
}
Series <
#{
self
.
series_class
}
; end
class ::
#{
subclass
}
Snapshot <
#{
self
.
snapshot_class
}
; end
"
)
subclass
.
instance_eval
do
...
...
lib/shotengai/series.rb
View file @
d28f79ad
...
...
@@ -43,18 +43,24 @@ module Shotengai
class
<<
self
def
inherited
subclass
@subclass
=
subclass
@product_name
=
/^(.+)Series$/
.
match
(
subclass
.
name
)[
1
]
add_associations
product_name
=
/^(.+)Series$/
.
match
(
subclass
.
name
)[
1
]
add_associations
(
subclass
,
product_name
)
# 加载自定义文件
require_custom_file
(
product_name
)
if
Rails
.
root
super
end
def
add_associations
def
add_associations
subclass
,
product_name
# belongs to Product
@subclass
.
belongs_to
:product
,
foreign_key: :shotengai_product_id
,
class_name:
@
product_name
,
touch:
true
@subclass
.
belongs_to
@product_name
.
underscore
.
to_sym
,
foreign_key: :shotengai_product_id
,
class_name:
@
product_name
,
touch:
true
subclass
.
belongs_to
:product
,
foreign_key: :shotengai_product_id
,
class_name:
product_name
,
touch:
true
subclass
.
belongs_to
product_name
.
underscore
.
to_sym
,
foreign_key: :shotengai_product_id
,
class_name:
product_name
,
touch:
true
# has many snapshot
@subclass
.
has_many
:snapshots
,
class_name:
"
#{
@product_name
}
Snapshot"
,
foreign_key: :shotengai_series_id
subclass
.
has_many
:snapshots
,
class_name:
"
#{
product_name
}
Snapshot"
,
foreign_key: :shotengai_series_id
end
def
require_custom_file
product_name
file_path
=
Rails
.
root
.
join
(
'app'
,
'models'
,
"
#{
product_name
}
_series.rb"
)
require
file_path
if
File
.
exist?
(
file_path
)
end
end
...
...
lib/shotengai/snapshot.rb
View file @
d28f79ad
...
...
@@ -60,8 +60,15 @@ module Shotengai
# belongs to Series
subclass
.
belongs_to
:series
,
foreign_key: :shotengai_series_id
,
class_name:
series_name
,
touch:
true
subclass
.
belongs_to
series_name
.
underscore
.
to_sym
,
foreign_key: :shotengai_series_id
,
class_name:
series_name
,
touch:
true
# 加载自定义文件
require_custom_file
(
product_name
)
if
Rails
.
root
super
end
def
require_custom_file
product_name
file_path
=
Rails
.
root
.
join
(
'app'
,
'models'
,
"
#{
product_name
}
_snapshot.rb"
)
require
file_path
if
File
.
exist?
(
file_path
)
end
end
# QUESTION: spec 赋值是在 after pay 合理?
...
...
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