lib/delorean/base.rb in delorean_lang-0.3.4 vs lib/delorean/base.rb in delorean_lang-0.3.5
- old
+ new
@@ -1,6 +1,7 @@
require 'active_support/time'
+require 'bigdecimal'
module Delorean
# FIXME: the whitelist is quite hacky. It's currently difficult to
# override it. A user will likely want to directly modify this
@@ -8,25 +9,25 @@
# rethought.
RUBY_WHITELIST = {
compact: [Array],
to_set: [Array],
flatten: [Array, [Fixnum, nil]],
- length: [[Array, String]],
+ length: [Enumerable],
max: [Array],
member: "member?",
- member?: [Array, [Fixnum, String]],
+ member?: [Array, [Object]],
reverse: [Array],
slice: [Array, Fixnum, Fixnum],
sort: [Array],
split: [String, String],
uniq: [Array],
sum: [Array],
zip: [Array, [Array, Array, Array]],
- index: [Array,
- [Integer, Numeric, String, Array, Fixnum, Hash]],
+ index: [Array, [Object]],
product: [Array, Array],
first: [Enumerable, [nil, Fixnum]],
+ last: [Enumerable, [nil, Fixnum]],
intersection: [Set, Enumerable],
union: [Set, Enumerable],
keys: [Hash],
values: [Hash],
@@ -115,9 +116,12 @@
return obj.send(attr.to_sym) if
klass.reflect_on_all_associations.map(&:name).member? attr.to_sym
elsif obj.instance_of?(NodeCall)
return obj.evaluate(attr)
elsif obj.instance_of?(Hash)
+ # FIXME: this implementation doesn't handle something like
+ # {}.length. i.e. length is a whitelisted function, but not
+ # an attr. This implementation returns nil instead of 0.
return obj[attr] if obj.member?(attr)
return attr.is_a?(String) ? obj[attr.to_sym] : nil
elsif obj.instance_of?(Class) && (obj < BaseClass)
return obj.send((attr + POST).to_sym, _e)
end