Commit 6d68782d by ivan Lan

Separate the product & series views template & Fix bug cause for the new json column changes

parent cea424ab
...@@ -3,17 +3,22 @@ module Shotengai ...@@ -3,17 +3,22 @@ module Shotengai
class << self class << self
def encode hash def encode hash
Harray.new( Harray.new(
if hash.is_a?(Hash)
hash.map {|key, val| { 'key' => key, 'val' => val } } hash.map {|key, val| { 'key' => key, 'val' => val } }
else
Array(hash)
end
) )
end end
def decode harray def decode harray
harray && Harray.new(harray).decode Harray.encode(harray).decode
end end
end end
# def initialize # def initialize *arg, &block
# # Add some validations # # Add some validations
# BUT HOW?
# end # end
def keys def keys
......
...@@ -11,7 +11,7 @@ module Shotengai ...@@ -11,7 +11,7 @@ module Shotengai
class_eval %Q{ class_eval %Q{
def #{column}= val def #{column}= val
raise Shotengai::WebError.new('#{column} 必须是个 Array', -1 , 401) unless val.nil? || Array === val raise Shotengai::WebError.new('#{column} 必须是个 Array', -1 , 401) unless val.nil? || Array === val
super(#{decode} ? Harray.decode(val) : val) super(#{decode} ? Shotengai::Harray.decode(val) : val)
end end
} }
end end
...@@ -38,7 +38,7 @@ module Shotengai ...@@ -38,7 +38,7 @@ module Shotengai
class_eval %Q{ class_eval %Q{
def #{key} def #{key}
{ {
template: #{template}, template: Shotengai::Harray.encode(#{template}).keys,
value: #{value}, value: #{value},
} }
end end
...@@ -51,7 +51,7 @@ module Shotengai ...@@ -51,7 +51,7 @@ module Shotengai
end end
keys.each do |key| keys.each do |key|
value = value_in_template ? "#{key}_template.decode" : "#{key}_value" 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
end end
end end
...@@ -69,11 +69,11 @@ module Shotengai ...@@ -69,11 +69,11 @@ module Shotengai
raise Shotengai::WebError.new('#{chimera} 必须是个 Hash', -1 , 401) unless val.nil? || Hash === val raise Shotengai::WebError.new('#{chimera} 必须是个 Hash', -1 , 401) unless val.nil? || Hash === val
write_attribute(:#{column}, val) write_attribute(:#{column}, val)
end end
# TODO: WARNING: 这里也 没有继承 之前方法的解析
def #{column}_before_implant def #{column}_before_implant
#{column} #{column}
end end
# WARNING: 默认值为 {}
define_method('#{column}') do define_method('#{column}') do
#{chimera}['#{as}'] || {} #{chimera}['#{as}'] || {}
end end
......
...@@ -40,7 +40,7 @@ module Shotengai ...@@ -40,7 +40,7 @@ module Shotengai
harray_accessor :info_template, :detail_info_template harray_accessor :info_template, :detail_info_template
harray_accessor :spec_value, :remark_value, decode: true harray_accessor :spec_value, :remark_value, decode: true
template_with_value_getters :info, value_in_template: true template_with_value_getters :info, :detail_info, value_in_template: true
template_with_value_getters :spec, :remark, delegate_template_to: :product template_with_value_getters :spec, :remark, delegate_template_to: :product
# full_info_template: { optional: d, detail: detail_info_template } # full_info_template: { optional: d, detail: detail_info_template }
......
...@@ -38,7 +38,7 @@ module Shotengai ...@@ -38,7 +38,7 @@ module Shotengai
validate :check_remark_value, unless: :remark_template_empty? validate :check_remark_value, unless: :remark_template_empty?
validates :count, numericality: { only_integer: true, greater_than: 0 } validates :count, numericality: { only_integer: true, greater_than: 0 }
template_with_value_getters :spec, :remark, :info, delegate_template_to: :series template_with_value_getters :spec, :remark, :info, :detail_info, delegate_template_to: :series
column_has_implants :meta, implants: ['product', 'series'], as: :snapshot column_has_implants :meta, implants: ['product', 'series'], as: :snapshot
column_has_implants :info_value, implants: ['detail'], as: :snapshot column_has_implants :info_value, implants: ['detail'], as: :snapshot
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment