Module: Rhino::Ruby::Scriptable

Included in:
Function, Object
Defined in:
lib/rhino/ruby.rb

Overview

shared JS::Scriptable implementation

Constant Summary collapse

@@access =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.accessObject


29
30
31
# File 'lib/rhino/ruby.rb', line 29

def self.access
  @@access ||= Ruby::DefaultAccess.new
end

.access=(access) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rhino/ruby.rb', line 9

def self.access=(access)
  @@access = ( access.respond_to?(:get) && access.respond_to?(:put) ) ? access : 
    begin
      access = 
        if access && ! access.is_a?(Class) # Scriptable.access = :attribute
          name = access.to_s.chomp('_access')
          name = name[0, 1].capitalize << name[1..-1]
          name = :"#{name}Access"
          if Ruby.const_defined?(name)
            Ruby.const_get(name) # e.g. Rhino::Ruby::AttributeAccess
          else
            const_get(name) # e.g. Rhino::Ruby::Scriptable::FooAccess
          end
        else # nil, false, Class
          access
        end
      access.is_a?(Class) ? access.new : access
    end
end

Instance Method Details

#get(name, start) ⇒ Object

override Object Scriptable#get(String name, Scriptable start); override Object Scriptable#get(int index, Scriptable start);


35
36
37
38
# File 'lib/rhino/ruby.rb', line 35

def get(name, start)
  return nil if exclude?(name)
  access.get(unwrap, name, self) { super }
end

#getIdsObject

override Object[] Scriptable#getIds();


55
56
57
58
59
60
61
62
63
64
# File 'lib/rhino/ruby.rb', line 55

def getIds
  ids = []
  unwrap.public_methods(false).each do |name| 
    next unless name = convert(name)
    name = name.to_s.to_java # java.lang.String
    ids << name unless ids.include?(name)
  end
  super.each { |id| ids.unshift(id) }
  ids.to_java
end

#has(name, start) ⇒ Object

override boolean Scriptable#has(String name, Scriptable start); override boolean Scriptable#has(int index, Scriptable start);


42
43
44
45
# File 'lib/rhino/ruby.rb', line 42

def has(name, start)
  return nil if exclude?(name)
  access.has(unwrap, name, self) { super }
end

#put(name, start, value) ⇒ Object

override void Scriptable#put(String name, Scriptable start, Object value); override void Scriptable#put(int index, Scriptable start, Object value);


49
50
51
52
# File 'lib/rhino/ruby.rb', line 49

def put(name, start, value)
  return nil if exclude?(name)
  access.put(unwrap, name, value) { super }
end