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
2c1add8d
Commit
2c1add8d
authored
Apr 19, 2018
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve :template_with_value about rewrite
parent
3369bc3d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
json_column.rb
lib/shotengai/json_column.rb
+9
-4
No files found.
lib/shotengai/json_column.rb
View file @
2c1add8d
...
@@ -34,7 +34,7 @@ module Shotengai
...
@@ -34,7 +34,7 @@ module Shotengai
harray_setter
*
columns
,
decode:
decode
harray_setter
*
columns
,
decode:
decode
end
end
def
template_with_value
key
,
value:
"
#{
key
}
_value"
,
template:
"
#{
key
}
_template"
,
trans:
nil
,
trans_to: :en
def
template_with_value
key
,
value:
"
#{
key
}
_value"
,
template:
"
#{
key
}
_template"
,
rewrite:
"
#{
key
}
_rewrite"
,
trans:
nil
,
trans_to: :en
trans_result
=
trans
.
is_a?
(
Hash
)
?
%Q{
trans_result
=
trans
.
is_a?
(
Hash
)
?
%Q{
{
{
#{
trans_to
}
_value: val&.reduce({}) do |o, obj|
#{
trans_to
}
_value: val&.reduce({}) do |o, obj|
...
@@ -44,19 +44,24 @@ module Shotengai
...
@@ -44,19 +44,24 @@ module Shotengai
end
end
}
}
}
:
'{}'
}
:
'{}'
# QUESTION: 在继承时 self will get (Object doesn't support #inspect)
has_rewrite_column
=
self
.
has_attribute?
(
rewrite
)
rescue
superclass
.
has_attribute?
(
rewrite
)
rewrite_key_val
=
has_rewrite_column
?
"rewrite:
#{
rewrite
}
"
:
''
class_eval
%Q{
class_eval
%Q{
def
#{
key
}
def
#{
key
}
val =
#{
value
}
.is_a?(Harray) ?
#{
value
}
.decode :
#{
value
}
val =
#{
value
}
.is_a?(Harray) ?
#{
value
}
.decode :
#{
value
}
{
{
template: Shotengai::Harray.encode(
#{
template
}
).keys,
template: Shotengai::Harray.encode(
#{
template
}
).keys,
value: val,
value: val,
}.merge(
#{
trans_result
}
).merge(try(:
#{
key
}
_rewrite) || {})
#{
rewrite_key_val
}
}.merge(
#{
trans_result
}
)
end
end
}
}
end
end
def
template_with_value_getters
*
keys
,
value_in_template:
false
,
delegate_template_to:
nil
,
trans:
nil
,
trans_to: :en
def
template_with_value_getters
*
keys
,
value_in_template:
false
,
delegate_template_to:
nil
,
rewrite:
nil
,
trans:
nil
,
trans_to: :en
if
delegate_template_to
if
delegate_template_to
self
.
delegate
(
*
keys
.
map
{
|
key
|
"
#{
key
}
_template"
},
to:
delegate_template_to
)
self
.
delegate
(
*
keys
.
map
{
|
key
|
"
#{
key
}
_template"
},
to:
delegate_template_to
)
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