Class: SparkleFormation::FunctionStruct
- Inherits:
-
AttributeStruct
- Object
- AttributeStruct
- SparkleFormation::FunctionStruct
- Defined in:
- lib/sparkle_formation/function_struct.rb
Overview
SparkleFormation customized AttributeStruct targeted at defining strings of code for remote evaulation
Instance Attribute Summary collapse
-
#_fn_args ⇒ Array<Object>
readonly
Function argument list.
-
#_fn_name ⇒ String
readonly
Name of function.
Instance Method Summary collapse
-
#[](val) ⇒ FunctionStruct
Set accessor directly into table data.
-
#_dump ⇒ String
Override of the dump to properly format eval string.
-
#_eval_join(*args) ⇒ String
Join arguments into a string for remote evaluation.
- #_klass ⇒ Class
-
#initialize(f_name = nil, *args) ⇒ self
constructor
Create a new FunctionStruct instance.
-
#method_missing(name, *args) ⇒ Object
Override to provide expected behavior when arguments are passed to a function call.
-
#nil? ⇒ False
Functions are never nil.
-
#root? ⇒ TrueClass, FalseClass
Is root struct.
Constructor Details
#initialize(f_name = nil, *args) ⇒ self
Create a new FunctionStruct instance
19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Override to provide expected behavior when arguments are passed to a function call
48 49 50 51 52 53 54 |
# File 'lib/sparkle_formation/function_struct.rb', line 48 def method_missing(name, *args) if(args.empty?) super else @table['_function_'] = _klass_new(name, *args) end end |
Instance Attribute Details
#_fn_args ⇒ Array<Object> (readonly)
Returns function argument list.
12 13 14 |
# File 'lib/sparkle_formation/function_struct.rb', line 12 def _fn_args @_fn_args end |
#_fn_name ⇒ String (readonly)
Returns name of function.
10 11 12 |
# File 'lib/sparkle_formation/function_struct.rb', line 10 def _fn_name @_fn_name end |
Instance Method Details
#[](val) ⇒ FunctionStruct
Set accessor directly into table data
60 61 62 |
# File 'lib/sparkle_formation/function_struct.rb', line 60 def [](val) _set("[#{val}]") end |
#_dump ⇒ String
Override of the dump to properly format eval string
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/sparkle_formation/function_struct.rb', line 67 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)) "'#{::Bogo::Utility.camel(arg.to_s, false)}'" elsif(arg.is_a?(::String)) "'#{arg}'" else arg.inspect end end.join(', ') unless(_fn_name.to_s.empty?) function_name = args.empty? ? "#{_fn_name}()" : "#{_fn_name}(#{args})" end internal = _eval_join( *[ function_name, suffix ].compact ) root? ? "[#{internal}]" : internal else suffix end end |
#_eval_join(*args) ⇒ String
Join arguments into a string for remote evaluation
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sparkle_formation/function_struct.rb', line 108 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 ⇒ Class
121 122 123 |
# File 'lib/sparkle_formation/function_struct.rb', line 121 def _klass ::SparkleFormation::FunctionStruct end |
#nil? ⇒ False
Returns functions are never nil.
33 34 35 |
# File 'lib/sparkle_formation/function_struct.rb', line 33 def nil? false end |
#root? ⇒ TrueClass, FalseClass
Returns is root struct.
38 39 40 |
# File 'lib/sparkle_formation/function_struct.rb', line 38 def root? _parent.nil? end |