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
fbaf667c
Commit
fbaf667c
authored
Aug 23, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use class_name as attributes instead of class itself
parent
6697ee3a
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
22 additions
and
20 deletions
+22
-20
.rspec_status
.rspec_status
+12
-12
shotengai.rb
lib/shotengai.rb
+1
-1
buyer.rb
lib/shotengai/buyer.rb
+2
-1
cart.rb
lib/shotengai/cart.rb
+2
-1
order.rb
lib/shotengai/order.rb
+3
-3
models_spec.rb
spec/shotengai/models_spec.rb
+2
-2
No files found.
.rspec_status
View file @
fbaf667c
example_id | status | run_time |
------------------------------------------ | ------ | --------------- |
./spec/shotengai/models_spec.rb[1:1:1:1] | passed | 0.36
278
seconds |
./spec/shotengai/models_spec.rb[1:1:1:2] | passed | 0.
24106
seconds |
./spec/shotengai/models_spec.rb[1:1:2:1] | passed | 0.19
389
seconds |
./spec/shotengai/models_spec.rb[1:1:2:2] | passed | 0.1
988
5 seconds |
./spec/shotengai/models_spec.rb[1:1:2:3] | passed | 0.
22058
seconds |
./spec/shotengai/models_spec.rb[1:1:3:1] | passed | 0.
202 seconds
|
./spec/shotengai/models_spec.rb[1:1:3:2] | passed | 0.
20022 seconds
|
./spec/shotengai/models_spec.rb[1:1:3:3] | passed | 0.20
972 seconds
|
./spec/shotengai/models_spec.rb[1:1:4:1] | passed | 0.2
3258
seconds |
./spec/shotengai/models_spec.rb[1:1:5:1] | passed | 0.
23735
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:1] | passed | 0.2
3552
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:2] | passed | 0.2
5856
seconds |
./spec/shotengai/models_spec.rb[1:1:1:1] | passed | 0.36
006
seconds |
./spec/shotengai/models_spec.rb[1:1:1:2] | passed | 0.
19221
seconds |
./spec/shotengai/models_spec.rb[1:1:2:1] | passed | 0.19
696
seconds |
./spec/shotengai/models_spec.rb[1:1:2:2] | passed | 0.1
774
5 seconds |
./spec/shotengai/models_spec.rb[1:1:2:3] | passed | 0.
17437
seconds |
./spec/shotengai/models_spec.rb[1:1:3:1] | passed | 0.
19322 seconds
|
./spec/shotengai/models_spec.rb[1:1:3:2] | passed | 0.
1998 seconds
|
./spec/shotengai/models_spec.rb[1:1:3:3] | passed | 0.20
12 seconds
|
./spec/shotengai/models_spec.rb[1:1:4:1] | passed | 0.2
2549
seconds |
./spec/shotengai/models_spec.rb[1:1:5:1] | passed | 0.
19514
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:1] | passed | 0.2
5054
seconds |
./spec/shotengai/models_spec.rb[1:1:5:2:2] | passed | 0.2
2609
seconds |
./spec/shotengai/models_spec.rb[1:2:1:1] | passed | 0.22996 seconds |
./spec/shotengai/models_spec.rb[1:2:1:2] | passed | 0.2075 seconds |
./spec/shotengai/models_spec.rb[1:2:2:1] | passed | 0.46901 seconds |
...
...
lib/shotengai.rb
View file @
fbaf667c
require
"shotengai/version"
require
'rails'
require
'active_record'
Dir
[
'./lib/shotengai/*'
].
each
{
|
f
|
require
f
}
Dir
[
'./lib/shotengai/*
.rb
'
].
each
{
|
f
|
require
f
}
module
Shotengai
# Your code goes here...
...
...
lib/shotengai/buyer.rb
View file @
fbaf667c
...
...
@@ -6,7 +6,8 @@ module Shotengai
end
class_methods
do
def
can_shopping_with
klass
,
options
=
{}
def
can_shopping_with
klass_name
,
options
=
{}
klass
=
Object
.
const_get
(
klass_name
)
unless
Shotengai
::
Order
<=>
klass
# 为子类
raise
ArgumentError
.
new
(
'You can only buy the class inherit from Shotengai::Order'
)
end
...
...
lib/shotengai/cart.rb
View file @
fbaf667c
...
...
@@ -24,7 +24,8 @@ module Shotengai
default_scope
{
where
(
status:
'cart'
)
}
class
<<
self
def
can_buy
*
good_classes
def
can_buy
*
good_class_names
good_classes
=
good_class_names
.
map
{
|
name
|
Object
.
const_get
(
name
)
}
# 所有snapshot
has_many
:snapshots
,
->
{
where
(
type:
good_classes
.
map
{
|
good_class
|
"
#{
good_class
.
name
}
Snapshot"
})
...
...
lib/shotengai/order.rb
View file @
fbaf667c
...
...
@@ -41,7 +41,6 @@ module Shotengai
end
def
fill_snapshot
p
'cmm 222'
ActiveRecord
::
Base
.
transaction
{
self
.
snapshots
.
each
(
&
:copy_info
)
}
...
...
@@ -80,7 +79,8 @@ module Shotengai
super
end
def
can_buy
*
good_classes
def
can_buy
*
good_class_names
good_classes
=
good_class_names
.
map
{
|
name
|
Object
.
const_get
(
name
)
}
# 所有snapshot
has_many
:snapshots
,
->
{
where
(
type:
good_classes
.
map
{
|
good_class
|
"
#{
good_class
.
name
}
Snapshot"
})
...
...
@@ -102,7 +102,7 @@ module Shotengai
)
end
self
.
cart_class
.
can_buy
*
good_classes
self
.
cart_class
.
can_buy
*
good_class
_nam
es
end
end
end
...
...
spec/shotengai/models_spec.rb
View file @
fbaf667c
...
...
@@ -29,12 +29,12 @@ RSpec.describe 'Shotengai Models' do
class
OtherGood
<
Shotengai
::
Product
;
end
class
TestOrder
<
Shotengai
::
Order
can_buy
::
TestGood
can_buy
'TestGood'
end
class
TestBuyer
<
ActiveRecord
::
Base
include
Shotengai
::
Buyer
can_shopping_with
::
TestOrder
can_shopping_with
'TestOrder'
ActiveRecord
::
Base
.
connection
.
create_table
(
:test_buyers
)
unless
ActiveRecord
::
Base
.
connection
.
table_exists?
(
:test_buyers
)
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