Module: Ruote::RubyDsl
- Defined in:
- lib/ruote/reader/ruby_dsl.rb
Overview
:nodoc:
Defined Under Namespace
Classes: BranchContext
Class Method Summary collapse
Class Method Details
.create_branch(name, attributes, &block) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ruote/reader/ruby_dsl.rb', line 120 def self.create_branch(name, attributes, &block) name = name[1..-1] while name[0, 1] == '_' h = attributes.inject({}) { |h1, a| a.is_a?(Hash) ? h1.merge!(a) : h1[a] = nil h1 }.inject({}) { |h1, (k, v)| k = k.is_a?(Regexp) ? k.inspect : k.to_s h1[k] = to_json(v) h1 } c = BranchContext.new(name, h) c.instance_eval(&block) if block c.to_a end |
.to_json(v) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ruote/reader/ruby_dsl.rb', line 144 def self.to_json(v) case v when Symbol; v.to_s when Regexp; v.inspect when Array; v.collect { |e| to_json(e) } when Hash; v.inject({}) { |h, (k, v)| h[k.to_s] = to_json(v); h } when Proc; v.to_raw_source + "\n" else v end end |