Class: Relisp::Proxy

Inherits:
Object show all
Defined in:
lib/relisp/type_conversion.rb

Overview

Proxy contains the code that creates a wrapper around a variable in emacs.

Direct Known Subclasses

Buffer, Cons, Frame, Marker, Overlay, Process, Window, WindowConfiguration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Proxy

If the last argument is a Relisp::Slave, it gets pulled off and used as the slave; otherwise Relisp.default_slave is used. If the first argument is a Symbol, it is assumed to be the name of an elisp variable which needs a proxy. If the first argument isn’t a Symbol, all of the arguments (except the last, if it was a Slave) are send off to the child to handle.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/relisp/type_conversion.rb', line 41

def initialize(*args)
  @slave = if args.last.kind_of?(Relisp::Slave)
             args.pop
           else
             Relisp.default_slave
           end

  if args[0].kind_of?(Symbol) && args[1].nil?
#        @elisp_variable = @slave.get_permanent_variable(args[0])
    @elisp_variable = args[0]
    elisp_type= ""
    self.class.to_s.split("::").last.split(//).each_with_index do |char, index|
      unless index==0 || char == char.downcase
        elisp_type << "-"
      end
      elisp_type << char.downcase
    end

    unless @slave.elisp_eval("(type-of #{@elisp_variable})") == elisp_type.to_sym
      raise ArgumentError, "#{@elisp_variable} isn't a #{elisp_type}"
    end
  else
    @elisp_variable = @slave.new_elisp_variable
    yield args
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(function, *args) ⇒ Object (private)



92
93
94
# File 'lib/relisp/type_conversion.rb', line 92

def method_missing(function, *args)
  call_on_self(function, *args)
end

Instance Attribute Details

#elisp_variableObject (readonly)

Returns the value of attribute elisp_variable.



68
69
70
# File 'lib/relisp/type_conversion.rb', line 68

def elisp_variable
  @elisp_variable
end

#slaveObject (readonly)

Returns the value of attribute slave.



68
69
70
# File 'lib/relisp/type_conversion.rb', line 68

def slave
  @slave
end

Class Method Details

.elisp_alias(ruby_name, elisp_name) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/relisp/type_conversion.rb', line 78

def self.elisp_alias(ruby_name, elisp_name)
  class_eval <<-EOM
    def #{ruby_name}
      call_on_self :#{elisp_name}
    end
  EOM
end

.from_elisp(object) ⇒ Object



29
30
31
32
# File 'lib/relisp/type_conversion.rb', line 29

def self.from_elisp(object)
  slave = object[:slave]
  new(slave.get_permanent_variable(object[:variable]), slave)
end

Instance Method Details

#makunboundObject



74
75
76
# File 'lib/relisp/type_conversion.rb', line 74

def makunbound
  @slave.makunbound @elisp_variable
end

#to_elispObject



70
71
72
# File 'lib/relisp/type_conversion.rb', line 70

def to_elisp
  @elisp_variable
end