Class: EacRubyUtils::CommonConstructor
- Inherits:
-
Object
- Object
- EacRubyUtils::CommonConstructor
show all
- Defined in:
- lib/eac_ruby_utils/common_constructor.rb,
lib/eac_ruby_utils/common_constructor/super_args.rb,
lib/eac_ruby_utils/common_constructor/class_accessors.rb,
lib/eac_ruby_utils/common_constructor/class_initialize.rb,
lib/eac_ruby_utils/common_constructor/instance_initialize.rb
Defined Under Namespace
Classes: ClassAccessors, ClassInitialize, InstanceInitialize, SuperArgs
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(*args, &after_set_block) ⇒ CommonConstructor
Returns a new instance of CommonConstructor.
38
39
40
41
42
43
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 38
def initialize(*args, &after_set_block)
args_processed = self.class.parse_args_options(args)
@all_args = args_processed.args
@options = args_processed.options
@after_set_block = after_set_block
end
|
Instance Attribute Details
#after_set_block ⇒ Object
Returns the value of attribute after_set_block.
10
11
12
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 10
def after_set_block
@after_set_block
end
|
Returns the value of attribute all_args.
10
11
12
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 10
def all_args
@all_args
end
|
Returns the value of attribute options.
10
11
12
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 10
def options
@options
end
|
Class Method Details
.parse_args_options(args) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 13
def parse_args_options(args)
result = ::Struct.new(:args, :options).new([], {})
options_reached = false
args.each do |arg|
raise "Options reached and there is more arguments (Arguments: #{args})" if
options_reached
options_reached = parse_arg_options_process_arg(result, arg)
end
result
end
|
Instance Method Details
45
46
47
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 45
def args
block_arg? ? all_args[0..-2] : all_args
end
|
#args_count ⇒ Object
49
50
51
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 49
def args_count
(args_count_min..args_count_max)
end
|
#args_count_max ⇒ Object
57
58
59
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 57
def args_count_max
args.count
end
|
#args_count_min ⇒ Object
53
54
55
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 53
def args_count_min
args.count - default_values.count
end
|
#block_arg ⇒ Object
61
62
63
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 61
def block_arg
block_arg? ? all_args.last : nil
end
|
65
66
67
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 65
def block_arg?
options[:block_arg] || false
end
|
#default_values ⇒ Object
69
70
71
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 69
def default_values
options[:default] || []
end
|
#setup_class(klass) ⇒ Object
73
74
75
76
77
78
79
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 73
def setup_class(klass)
setup_class_accessors(klass)
setup_class_initialize(klass)
klass
end
|
#setup_class_accessors(klass) ⇒ Object
#setup_class_initialize(klass) ⇒ Object
#super_args ⇒ Object
89
90
91
|
# File 'lib/eac_ruby_utils/common_constructor.rb', line 89
def super_args
options[:super_args]
end
|