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
1ecc6c20
Commit
1ecc6c20
authored
Nov 21, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add trans to JsonColumn :template_with_value_getters
parent
08e5d668
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
4 deletions
+12
-4
json_column.rb
lib/shotengai/json_column.rb
+12
-4
No files found.
lib/shotengai/json_column.rb
View file @
1ecc6c20
...
...
@@ -34,26 +34,34 @@ module Shotengai
harray_setter
*
columns
,
decode:
decode
end
def
template_with_value
key
,
value:
"
#{
key
}
_value"
,
template:
"
#{
key
}
_template"
def
template_with_value
key
,
value:
"
#{
key
}
_value"
,
template:
"
#{
key
}
_template"
,
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
}
:
{}
class_eval
%Q{
def
#{
key
}
val =
#{
value
}
.is_a?(Harray) ?
#{
value
}
.decode :
#{
value
}
{
template: Shotengai::Harray.encode(
#{
template
}
).keys,
value: val,
}
}
.merge(
#{
trans_result
}
)
end
}
end
def
template_with_value_getters
*
keys
,
value_in_template:
false
,
delegate_template_to:
nil
def
template_with_value_getters
*
keys
,
value_in_template:
false
,
delegate_template_to:
nil
,
trans:
nil
,
trans_to: :en
if
delegate_template_to
self
.
delegate
(
*
keys
.
map
{
|
key
|
"
#{
key
}
_template"
},
to:
delegate_template_to
)
end
keys
.
each
do
|
key
|
value
=
value_in_template
?
"Shotengai::Harray.decode(
#{
key
}
_template)"
:
"
#{
key
}
_value"
self
.
template_with_value
key
,
value:
value
self
.
template_with_value
key
,
value:
value
,
trans:
trans
,
trans_to:
trans_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