Class: Aspera::Cli::AttrAccessor

Inherits:
Object
  • Object
show all
Defined in:
lib/aspera/cli/manager.rb

Overview

option is retrieved from another object using accessor

Instance Method Summary collapse

Constructor Details

#initialize(object, method_name, option_name) ⇒ AttrAccessor

attr_accessor :object attr_accessor :method_name



18
19
20
21
22
23
24
25
# File 'lib/aspera/cli/manager.rb', line 18

def initialize(object, method_name, option_name)
  @object = object
  @method = method_name
  @option_name = option_name
  @has_writer = @object.respond_to?(writer_method)
  Log.log.trace1{"AttrAccessor: #{@option_name}: #{@object.class}.#{@method}: writer=#{@has_writer}"}
  Aspera.assert(@object.respond_to?(@method)) {"#{object} does not respond to #{method_name}"}
end

Instance Method Details

#valueObject



27
28
29
30
# File 'lib/aspera/cli/manager.rb', line 27

def value
  return @object.send(@method) if @has_writer
  return @object.send(@method, @option_name, :get)
end

#value=(val) ⇒ Object



32
33
34
35
36
# File 'lib/aspera/cli/manager.rb', line 32

def value=(val)
  Log.log.trace1{"AttrAccessor: = #{@method} #{@option_name} :set #{val}, writer=#{@has_writer}"}
  return @object.send(writer_method, val) if @has_writer
  return @object.send(@method, @option_name, :set, val)
end

#writer_methodObject



38
39
40
# File 'lib/aspera/cli/manager.rb', line 38

def writer_method
  return "#{@method}="
end