Class: RuleBox::UseCaseBase
- Inherits:
-
Object
- Object
- RuleBox::UseCaseBase
- Includes:
- Mapper
- Defined in:
- lib/rule_box/use_case_base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attribute_names ⇒ Object
- #attributes ⇒ Object
-
#initialize(**args) ⇒ UseCaseBase
constructor
A new instance of UseCaseBase.
- #to_s ⇒ Object
Methods included from Mapper
Methods included from ExecutionHook
Constructor Details
#initialize(**args) ⇒ UseCaseBase
Returns a new instance of UseCaseBase.
7 8 9 10 11 12 |
# File 'lib/rule_box/use_case_base.rb', line 7 def initialize(**args) args.each do |key, value| key = key.to_s attributes[key] = value if attribute_names.include? key end end |
Class Method Details
.attributes(*names) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/rule_box/use_case_base.rb', line 32 def attributes(*names) names = names.map(&:to_s) define_method(:attribute_names) { names } names.each do |name| define_method(name) { attributes[name] } define_method("#{name}=") { |value| attributes[name] = value } end end |
Instance Method Details
#attribute_names ⇒ Object
23 24 25 |
# File 'lib/rule_box/use_case_base.rb', line 23 def attribute_names [] end |
#attributes ⇒ Object
27 28 29 |
# File 'lib/rule_box/use_case_base.rb', line 27 def attributes @attributes ||= {} end |
#to_s ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/rule_box/use_case_base.rb', line 14 def to_s names = self.class.name.split('::').reverse.join names.gsub(/::/, '/') .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr('-', '_') .downcase end |