Class: DevSystem::MethodShell

Inherits:
Shell show all
Defined in:
lib/dev_system/subsystems/shell/shells/method_shell.rb

Defined Under Namespace

Classes: NotFoundError

Instance Attribute Summary collapse

Attributes inherited from Liza::Controller

#menv

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Shell

all, cruby?, engine, jruby?, linux?, mac?, os, ruby_version, unix?, windows?

Methods inherited from Liza::Controller

#`, `, attr_accessor, attr_reader, attr_writer, #attrs, box, #box, call, color, division, division!, division?, inherited, menv_accessor, menv_reader, menv_writer, on_connected, panel, #panel, plural, require, requirements, sh, #sh, singular, subsystem, subsystem!, subsystem?, subsystem_token, token

Methods inherited from Liza::Unit

_erbs_for, #add, add, cl, #cl, class_methods_defined, const_added, const_missing, constants_defined, define_error, descendants_select, division, erbs_available, erbs_defined, erbs_for, errors, #fetch, fetch, get, #get, instance_methods_defined, log, #log, log?, #log?, #log_array, log_array, log_hash, #log_hash, #log_level, log_level, #log_level?, log_level?, log_levels, #log_levels, #log_render_convert, #log_render_format, #log_render_in, #log_render_out, method_added, methods_defined, namespace, part, raise_error, #raise_error, reload!, #reload!, #render, #render!, #render_stack, renderable_formats_for, renderable_names, section, sections, #set, set, #settings, settings, singleton_method_added, sleep, #sleep, stick, #stick, sticks, #sticks, subclasses_select, subunits, system, #system, system?, test_class, time_diff, #time_diff

Constructor Details

#initialize(object, method_name) ⇒ MethodShell

Returns a new instance of MethodShell.



15
16
17
18
19
20
21
22
23
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 15

def initialize(object, method_name)
  super()
  @object = object
  @method_name = method_name
  
  @method = object.method method_name
rescue NameError
  raise NotFoundError, "method not found: #{method_name.inspect}", caller
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



13
14
15
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 13

def method_name
  @method_name
end

#objectObject (readonly)

Returns the value of attribute object.



13
14
15
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 13

def object
  @object
end

Class Method Details

.signature_has_single_parameter_named?(object, method_name, arg_name) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 6

def self.signature_has_single_parameter_named?(object, method_name, arg_name)
  return false unless object.respond_to? method_name
  new(object, method_name).signature_has_single_parameter_named?(arg_name)
end

Instance Method Details

#lineObject



34
35
36
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 34

def line
  @line ||= File.readlines(@method.source_location[0])[@method.source_location[1] - 1].strip
end

#line_locationObject



38
39
40
41
42
43
44
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 38

def line_location
  @line_location ||= begin
    path = @method.source_location[0].gsub(App.root.to_s, "")[1..-1]
    line_number = @method.source_location[1]
    "#{path}:#{line_number}"
  end
end

#method(sym = nil) ⇒ Object



27
28
29
30
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 27

def method(sym=nil)
  return super if sym
  @method
end

#signature_has_single_parameter_named?(name) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/dev_system/subsystems/shell/shells/method_shell.rb', line 48

def signature_has_single_parameter_named?(name)
  @method.parameters == [[:req, name]]
end