class SparkleFormation::FunctionStruct

SparkleFormation customized AttributeStruct targeted at defining strings of code for remote evaulation

Attributes

_fn_args[R]

@return [Array<Object>] function argument list

_fn_name[R]

@return [String] name of function

Public Class Methods

new(f_name = nil, *args) click to toggle source

Create a new FunctionStruct instance

@param f_name [String] name of function @param args [Array<Object>] argument list @return [self]

Calls superclass method
# File lib/sparkle_formation/function_struct.rb, line 19
def initialize(f_name = nil, *args)
  super()
  @_fn_name = f_name.to_s
  @_fn_args = args
  @_fn_args.map! do |l_arg|
    if l_arg.is_a?(_klass)
      l_arg = l_arg._root
      l_arg._parent(self)
    end
    l_arg
  end
end

Public Instance Methods

==(_other) click to toggle source

@return [TrueClass, FalseClass]

# File lib/sparkle_formation/function_struct.rb, line 70
def ==(_other)
  eql?(_other)
end
[](val) click to toggle source

Set accessor directly into table data

@param val [Integer, String] @return [FunctionStruct]

# File lib/sparkle_formation/function_struct.rb, line 102
def [](val)
  if val.is_a?(::String) && __single_quote_strings
    _set("['#{val}']")
  else
    _set("[#{val.inspect}]")
  end
end
__anchor_start() click to toggle source

@return [String] start character(s) used to anchor function call

# File lib/sparkle_formation/function_struct.rb, line 191
def __anchor_start
  "["
end
__anchor_stop() click to toggle source

@return [String] stop character(s) used to anchor function call

# File lib/sparkle_formation/function_struct.rb, line 196
def __anchor_stop
  "]"
end
__empty_argument_list() click to toggle source

@return [String] value to use when argument list is empty

# File lib/sparkle_formation/function_struct.rb, line 201
def __empty_argument_list
  "()"
end
__quote_nested_funcs?() click to toggle source
# File lib/sparkle_formation/function_struct.rb, line 176
def __quote_nested_funcs?
  false
end
__single_anchor?() click to toggle source

@return [TrueClass] wrap in single anchor

# File lib/sparkle_formation/function_struct.rb, line 181
def __single_anchor?
  true
end
__single_quote_strings() click to toggle source

@return [TrueClass] enable single quote string generation

# File lib/sparkle_formation/function_struct.rb, line 216
def __single_quote_strings
  true
end
_clone(*_) click to toggle source

Create a clone of this instance

# File lib/sparkle_formation/function_struct.rb, line 33
def _clone(*_)
  new_inst = _klass_new(_fn_name, *_fn_args)
  new_inst._data.replace(__hashish[
    @table.map { |_key, _value|
      if _key.is_a?(::AttributeStruct)
        _key = _key._clone
      else
        _key = _do_dup(_key)
      end
      if _value.is_a?(::AttributeStruct)
        _value = _value._clone
      else
        _value = _do_dup(_value)
      end
      [_key, _value]
    }
  ])
  new_inst
end
_dump() click to toggle source

Override of the dump to properly format eval string

@return [String]

# File lib/sparkle_formation/function_struct.rb, line 113
def _dump
  unless @table.empty?
    key, value = @table.first
    suffix = _eval_join(
      *[
      key == "_function_" ? nil : key,
      !value.nil? ? value._dump : nil,
    ].compact
    )
  end
  if _fn_name
    args = _fn_args.map do |arg|
      if arg.respond_to?(:_dump)
        arg._dump
      elsif arg.is_a?(::Symbol)
        quote = __single_quote_strings ? "'" : '"'
        "#{quote}#{::Bogo::Utility.camel(arg.to_s, false)}#{quote}"
      elsif arg.is_a?(::String) && __single_quote_strings
        "'#{arg}'"
      else
        arg.inspect
      end
    end.join(", ")
    unless _fn_name.to_s.empty?
      function_name = args.empty? ? "#{_fn_name}#{__empty_argument_list}" : "#{_fn_name}(#{args})"
    end
    internal = _eval_join(
      *[
      function_name,
      suffix,
    ].compact
    )
    if root? || (!__single_anchor? && function_name)
      if !root? && __quote_nested_funcs?
        quote = __single_quote_strings ? "'" : '"'
      end
      "#{quote}#{__anchor_start}#{internal}#{__anchor_stop}#{quote}"
    else
      internal
    end
  else
    suffix
  end
end
Also aliased as: _sparkle_dump
_eval_join(*args) click to toggle source

Join arguments into a string for remote evaluation

@param args [Array<String>] @return [String]

# File lib/sparkle_formation/function_struct.rb, line 164
def _eval_join(*args)
  args = args.compact
  args.delete_if &:empty?
  args.slice(1, args.size).to_a.inject(args.first) do |memo, item|
    if item.start_with?("[")
      memo += item
    else
      memo += ".#{item}"
    end
  end
end
_klass() click to toggle source

@return [Class]

# File lib/sparkle_formation/function_struct.rb, line 186
def _klass
  ::SparkleFormation::FunctionStruct
end
_sparkle_dump()
Alias for: _dump
eql?(_other) click to toggle source

@return [TrueClass, FalseClass]

# File lib/sparkle_formation/function_struct.rb, line 59
def eql?(_other)
  if _other.respond_to?(:_dump) && _other.respond_to?(:_parent)
    ::MultiJson.dump(_dump).hash ==
      ::MultiJson.dump(_other._dump).hash &&
      _parent == _other._parent
  else
    false
  end
end
hash() click to toggle source

@return [Numeric] hash value for instance

# File lib/sparkle_formation/function_struct.rb, line 54
def hash
  _dump.hash
end
inspect() click to toggle source

@return [String] dump from root

# File lib/sparkle_formation/function_struct.rb, line 211
def inspect
  _root._dump
end
method_missing(name, *args) click to toggle source

Override to provide expected behavior when arguments are passed to a function call

@param name [String, Symbol] method name @param args [Object<Array>] argument list @return [Object]

Calls superclass method
# File lib/sparkle_formation/function_struct.rb, line 90
def method_missing(name, *args)
  if args.empty?
    super
  else
    @table["_function_"] = _klass_new(name, *args)
  end
end
nil?() click to toggle source

@return [False] functions are never nil

# File lib/sparkle_formation/function_struct.rb, line 75
def nil?
  false
end
root?() click to toggle source

@return [TrueClass, FalseClass] is root struct

# File lib/sparkle_formation/function_struct.rb, line 80
def root?
  _parent.nil?
end
to_s() click to toggle source

@return [String] dump from root

# File lib/sparkle_formation/function_struct.rb, line 206
def to_s
  _root._dump
end