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
573e9d08
Commit
573e9d08
authored
Apr 20, 2018
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve JsonColumn code style and add reader "#{key}_rewrited"
parent
b99bf278
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
10 deletions
+21
-10
harray.rb
lib/shotengai/harray.rb
+4
-0
json_column.rb
lib/shotengai/json_column.rb
+17
-10
No files found.
lib/shotengai/harray.rb
View file @
573e9d08
...
...
@@ -45,5 +45,9 @@ module Shotengai
def
hash_map
self
.
map
{
|
obj
|
yield
obj
[
'key'
],
obj
[
'val'
]}
end
def
merge
hash
self
.
decode
.
merge
(
hash
)
end
end
end
lib/shotengai/json_column.rb
View file @
573e9d08
...
...
@@ -36,28 +36,35 @@ module Shotengai
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_to
}
_value: val&.reduce({}) do |o, obj|
trans =
#{
trans
}
val = obj[1].is_a?(Array) ? obj[1].map{ |x| trans[x] } : trans[ obj[1] ]
o.merge( obj[0] => val )
end
}
}
:
'{}'
#{
trans_to
}
_value: val&.reduce({}) do |o, obj|
val = obj[1].is_a?(Array) ? obj[1].map{ |x|
#{
trans
}
[x] } :
#{
trans
}
[ obj[1] ]
o.merge( obj[0] => val )
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
}
"
:
''
rewrite_key_val
,
define_rewrited_reader
=
if
has_rewrite_column
[
"rewrite:
#{
rewrite
}
,"
,
"def
#{
key
}
_rewrited;
#{
value
}
.merge(
#{
rewrite
}
); end;"
]
end
class_eval
%Q{
def
#{
key
}
val =
#{
value
}
.is_a?(Harray) ?
#{
value
}
.decode :
#{
value
}
{
template: Shotengai::Harray.encode(
#{
template
}
).keys,
value: val,
#{
trans_result
}
#{
rewrite_key_val
}
}
.merge(
#{
trans_result
}
)
}
end
#{
define_rewrited_reader
}
}
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