app/models/concerns/hancock/hash_field.rb in hancock_cms-1.0.2.3 vs app/models/concerns/hancock/hash_field.rb in hancock_cms-2.0.0
- old
+ new
@@ -1,10 +1,10 @@
if Hancock.mongoid?
module Hancock::HashField
extend ActiveSupport::Concern
- class_methods do
+ module ClassMethods
def hancock_cms_hash_field(name, opts = {})
opts.merge!({type: Hash, default: {}})
field "#{name}_hash", opts
meth = name
@@ -12,11 +12,11 @@
meth_hsh = "#{name}_hash".freeze
meth_json = "#{name}_json".freeze
if opts[:localize]
meth_str_t = "#{meth_str}_translations".freeze
meth_hsh_t = "#{meth_hsh}_translations".freeze
- class_eval <<-RUBY
+ class_eval <<-EVAL
def #{meth_str_t}=(val)
return self.#{meth_hsh_t} = {} if val.blank?
_hash = {}
self[:#{meth_str_t}] ||= {}
I18n.available_locales.each do |l|
@@ -61,14 +61,14 @@
end
self.remove_attribute :#{meth_str_t} unless _has_errors
end
true
end
- RUBY
+ EVAL
else
- class_eval <<-RUBY
+ class_eval <<-EVAL
def #{meth_str}=(val)
return self.#{meth_hsh} = {} if val.blank?
if val.is_a?(String)
begin
begin
@@ -103,12 +103,11 @@
self.remove_attribute :#{meth_str}
end
true
end
end
- RUBY
- end #if opts[:localize]
- end #def hancock_cms_hash_field(name, opts = {})
- end # class_methods do
-
+ EVAL
+ end
+ end
+ end
end
end