class Ducktape::Expression::IdentifierExp
Public Instance Methods
bind(src, type, qual = nil, _ = src)
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 6 def bind(src, type, qual = nil, _ = src) unbind @source, @type, @qual = WeakReference.new(src), type, qual case when src.is_a?(Bindable) && src.bindable_attr?(literal) then src.on_changed(literal, self) when src.is_a?(Hookable) then src.on_changed(self) end value end
call(parms)
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 31 def call(parms) return unless parms[:attribute].to_s == literal.to_s owner.send("#{@type}_changed") nil end
rightmost()
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 37 def rightmost self end
unbind()
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 18 def unbind return unless @source src = @source.object return @source, @type, @qual = nil unless src case when src.is_a?(Bindable) && src.bindable_attr?(literal) then src.unhook_on_changed(literal, self) when src.is_a?(Hookable) then src.remove_hook(:on_changed, self) end @source, @type, @qual = nil end
unparse()
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 41 def unparse literal end
value()
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 45 def value src = source case @qual when QualifiedExp then src.const_get(literal) when PropertyExp then src.public_send(literal) else is_constant?(src) ? src.const_get(literal) : src.public_send(literal) end end
value=(value)
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 54 def value=(value) src = source return unless @type == :value case @qual when QualifiedExp then src.const_set(literal, value) when PropertyExp then property_set(src, value) else is_constant?(src) ? src.const_set(literal, value) : property_set(src, value) end nil end
Protected Instance Methods
source()
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 68 def source raise UnboundError unless @source src = @source.object raise UnboundError unless src src end
Private Instance Methods
is_constant?(src)
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 76 def is_constant?(src) literal =~ /^[A-Z]/ && # starts with capital? src.respond_to?(:const_defined?) && # source can check for constants (Class, Module)? src.const_defined?(literal) # check to see if constant exists end
property_set(src, value)
click to toggle source
# File lib/ducktape/expression/identifier_exp.rb, line 82 def property_set(src, value) case when src.is_a?(Bindable) && src.bindable_attr?(literal) src.send(:get_bindable_attr, literal).set_value value when src.respond_to?("#{literal}=") src.public_send("#{literal}=", value) when src.respond_to?(literal) && [-2, -1, 1].include?(src.public_method(literal).arity) src.public_send(literal, value) else nil # nothing to do end end