Module: TurfJS
- Defined in:
- lib/turfjs.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
- .context ⇒ Object
- .method_missing(method, *args) ⇒ Object
- .respond_to_missing?(method, include_private = false) ⇒ Boolean
- .turf_api_mapping ⇒ Object
Class Method Details
.context ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/turfjs.rb', line 8 def self.context @context ||= begin source = File.read(File.('turfjs-build.js', __dir__)) ExecJS.compile(source) end end |
.method_missing(method, *args) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/turfjs.rb', line 23 def self.method_missing(method, *args) turf_api_name = turf_api_mapping[method] return super unless turf_api_name begin context.call("turf.#{turf_api_name}", *args) rescue ExecJS::ProgramError => e raise Error, e. end end |
.respond_to_missing?(method, include_private = false) ⇒ Boolean
34 35 36 |
# File 'lib/turfjs.rb', line 34 def self.respond_to_missing?(method, include_private = false) turf_api_mapping.keys.include?(method) || super end |
.turf_api_mapping ⇒ Object
16 17 18 19 20 21 |
# File 'lib/turfjs.rb', line 16 def self.turf_api_mapping @turf_api_mapping ||= context.call('turfAPIs').map do |name| [name.underscore.to_sym, name] end.to_h end |