Module: ValueClass::ClassMethods
- Defined in:
- lib/value_class.rb
Instance Method Summary collapse
- #config_help(prefix = "") ⇒ Object
- #declare_comparison_operators ⇒ Object
- #inherited(new_child_class) ⇒ Object
- #value_attr(attribute_name, options = {}) ⇒ Object
- #value_attributes ⇒ Object
- #value_attrs(*args) ⇒ Object
- #value_description(value = nil) ⇒ Object
- #value_list_attr(attribute_name, options = {}) ⇒ Object
Instance Method Details
#config_help(prefix = "") ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/value_class.rb', line 87 def config_help(prefix = "") [ "#{name}: #{value_description}", " attributes:", value_attributes.map { |ca| ca.description(prefix + " ") } ].flatten.join("\n") + "\n" end |
#declare_comparison_operators ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/value_class.rb', line 99 def declare_comparison_operators unless @comparison_operators_declared @comparison_operators_declared = true include AttrComparable attr_compare(value_attributes.map(&:name)) end end |
#inherited(new_child_class) ⇒ Object
108 109 110 |
# File 'lib/value_class.rb', line 108 def inherited(new_child_class) value_attributes.each { |attr| new_child_class.value_attributes << attr } end |
#value_attr(attribute_name, options = {}) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/value_class.rb', line 75 def value_attr(attribute_name, = {}) attribute = Attribute.new(attribute_name, ) value_attributes << attribute attr_reader(attribute.name) end |
#value_attributes ⇒ Object
95 96 97 |
# File 'lib/value_class.rb', line 95 def value_attributes @value_attributes ||= [] end |
#value_attrs(*args) ⇒ Object
82 83 84 85 |
# File 'lib/value_class.rb', line 82 def value_attrs(*args) = args.last.is_a?(::Hash) ? args.pop : {} args.each { |arg| value_attr(arg, ) } end |
#value_description(value = nil) ⇒ Object
64 65 66 67 68 69 |
# File 'lib/value_class.rb', line 64 def value_description(value = nil) if value @value_description = value end @value_description end |
#value_list_attr(attribute_name, options = {}) ⇒ Object
71 72 73 |
# File 'lib/value_class.rb', line 71 def value_list_attr(attribute_name, = {}) value_attr(attribute_name, .merge(default: [], class_name: nil, list_of_class: [:class_name])) end |