Class: EacRubyUtils::CommonConstructor::ClassAccessors

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/common_constructor/class_accessors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(common_constructor, klass) ⇒ ClassAccessors

Returns a new instance of ClassAccessors.



11
12
13
14
# File 'lib/eac_ruby_utils/common_constructor/class_accessors.rb', line 11

def initialize(common_constructor, klass)
  @common_constructor = common_constructor
  @klass = klass
end

Instance Attribute Details

#common_constructorObject (readonly)

Returns the value of attribute common_constructor.



9
10
11
# File 'lib/eac_ruby_utils/common_constructor/class_accessors.rb', line 9

def common_constructor
  @common_constructor
end

#klassObject (readonly)

Returns the value of attribute klass.



9
10
11
# File 'lib/eac_ruby_utils/common_constructor/class_accessors.rb', line 9

def klass
  @klass
end

Instance Method Details

#argsObject



16
17
18
# File 'lib/eac_ruby_utils/common_constructor/class_accessors.rb', line 16

def args
  common_constructor.all_args
end

#performObject



20
21
22
23
# File 'lib/eac_ruby_utils/common_constructor/class_accessors.rb', line 20

def perform
  setup_class_attr_readers
  setup_class_attr_writers
end

#setup_class_attr_readersObject



25
26
27
28
# File 'lib/eac_ruby_utils/common_constructor/class_accessors.rb', line 25

def setup_class_attr_readers
  klass.send(:attr_reader, *args)
  klass.send(:public, *args) if args.any?
end

#setup_class_attr_writersObject



30
31
32
33
# File 'lib/eac_ruby_utils/common_constructor/class_accessors.rb', line 30

def setup_class_attr_writers
  klass.send(:attr_writer, *args)
  klass.send(:private, *args.map { |a| "#{a}=" }) if args.any?
end