Sha256: 2087ef8ada505cb448a61017dc2bd54bdf7d2f73958d4f547692d479b9205b84
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
class Jcompiler::Provider def initialize @context = nil end def object!(arg_src = nil, &block) pre_context = @context @context = [] srcs, subst_src = if arg_src [block.call(nil), "#{block.parameters[0][1]}=(#{arg_src});"] else [block.call, ''] end @context = pre_context %{"{\#{#{subst_src}[#{srcs.join(',')}].join(',')}}"} end def array!(arg_src, &block) item_name = block.parameters[0][1].to_s src = block.call(nil) %{"[\#{(#{arg_src}).map { |#{item_name}| #{src} }.join(',')}]"} end def number!(num) %{num.to_json} end def string!(str) %{str.to_json} end def extract!(obj_name, *key_names) key_names.each do |key_name| send(key_name, "#{obj_name}.#{key_name}") end end def method_missing(name, *args, &block) src = if block block.call else args[0] end @context << %{"\\"#{name}\\":\#{(#{src}).to_json}"} end protected def value! end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jcompiler-0.1.120 | lib/jcompiler/provider.rb |