Class: RamlParser::Parser
- Inherits:
-
Object
- Object
- RamlParser::Parser
- Defined in:
- lib/raml_parser.rb
Class Method Summary collapse
- .alter_string(str, params, node) ⇒ Object
- .is_method(key) ⇒ Object
- .is_resource(key) ⇒ Object
- .parse_file(path) ⇒ Object
- .parse_file_with_marks(path) ⇒ Object
- .traverse(raw, params, node) ⇒ Object
Class Method Details
.alter_string(str, params, node) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/raml_parser.rb', line 240 def self.alter_string(str, params, node) str.gsub(/<<([a-zA-Z]+)(\s*\|\s*!([a-zA-Z_\-]+))?>>/) do |a,b| case $3 when nil params[$1].to_s when 'singularize' params[$1].to_s.singularize when 'pluralize' params[$1].to_s.pluralize else raise "Using unknown parametrization function #{$3} at #{node.path}" end end end |
.is_method(key) ⇒ Object
278 279 280 |
# File 'lib/raml_parser.rb', line 278 def self.is_method(key) %w(get post put delete head patch options trace connect).include? key end |
.is_resource(key) ⇒ Object
271 272 273 |
# File 'lib/raml_parser.rb', line 271 def self.is_resource(key) key =~ /^\// end |
.parse_file(path) ⇒ Object
6 7 8 9 10 |
# File 'lib/raml_parser.rb', line 6 def self.parse_file(path) ensure_raml_0_8(path) node = YamlNode.new(nil, 'root', YamlHelper.read_yaml(path)) parse_root(node) end |
.parse_file_with_marks(path) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/raml_parser.rb', line 12 def self.parse_file_with_marks(path) ensure_raml_0_8(path) node = YamlNode.new(nil, 'root', YamlHelper.read_yaml(path)) node.mark_all(:unused) node.mark(:used) root = parse_root(node) { :root => root, :marks => node.marks } end |
.traverse(raw, params, node) ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/raml_parser.rb', line 255 def self.traverse(raw, params, node) if raw.is_a? Hash Hash[raw.map { |k,v| [traverse(k, params, node), traverse(v, params, node)] }] elsif raw.is_a? Array raw.map { |i| traverse(i, params, node) } elsif raw.is_a? String alter_string(raw, params, node) else raw end end |