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
762444fe
Commit
762444fe
authored
Sep 07, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the nested inheriting about series and snapshot
parent
daa37e9f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
6 deletions
+33
-6
.rspec_status
.rspec_status
+1
-0
product.rb
lib/shotengai/product.rb
+9
-2
models_spec.rb
spec/shotengai/models_spec.rb
+23
-4
No files found.
.rspec_status
View file @
762444fe
...
...
@@ -16,3 +16,4 @@ example_id | status | run_time |
./spec/shotengai/models_spec.rb[1:2:1:2] | passed | 0.3256 seconds |
./spec/shotengai/models_spec.rb[1:2:2:1] | passed | 0.62601 seconds |
./spec/shotengai/models_spec.rb[1:2:2:2] | passed | 0.45201 seconds |
./spec/shotengai/models_spec.rb[1:3:1] | passed | 0.48308 seconds |
lib/shotengai/product.rb
View file @
762444fe
...
...
@@ -64,6 +64,13 @@ module Shotengai
end
class
<<
self
def
series_class
Shotengai
::
Series
end
def
snapshot_class
Shotengai
::
Snapshot
end
# TODO: ::#{subclass}Series 增加命名规则定义 降低耦合性??
def
inherited
(
subclass
)
# 创建相关 series 与 snapshot
...
...
@@ -75,8 +82,8 @@ module Shotengai
def
define_related_class
subclass
# Useing Class.new could not get class_name in self.inherited
class_eval
(
"
class ::
#{
subclass
}
Series <
Shotengai::Series
; end;
class ::
#{
subclass
}
Snapshot <
Shotengai::Snapshot
; end
class ::
#{
subclass
}
Series <
#{
self
.
series_class
}
; end;
class ::
#{
subclass
}
Snapshot <
#{
self
.
snapshot_class
}
; end
"
)
subclass
.
instance_eval
do
def
series_class
;
"
#{
self
.
name
}
Series"
.
constantize
;
end
...
...
spec/shotengai/models_spec.rb
View file @
762444fe
...
...
@@ -266,6 +266,29 @@ RSpec.describe 'Shotengai Models' do
end
end
describe
'Nested Inherited'
do
before
do
class
Good
<
Shotengai
::
Product
;
end
class
NestedGood
<
Good
;
end
class
GoodSeries
def
a
'outside a'
end
end
class
NestedGoodSeries
<
GoodSeries
def
a
'nested a'
end
end
end
it
'does something'
do
expect
(
GoodSeries
.
new
.
a
).
to
eq
(
'outside a'
)
expect
(
NestedGoodSeries
.
new
.
a
).
to
eq
(
'nested a'
)
end
end
after
do
ActiveRecord
::
Migration
[
5.1
].
subclasses
.
each
do
|
migrate
|
migrate
.
migrate
(
:down
)
...
...
@@ -273,6 +296,3 @@ RSpec.describe 'Shotengai Models' do
end
end
# ActiveRecord::Migration[5.1].subclasses.each do |migrate|
# migrate.migrate(:down)
# end
\ No newline at end of file
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