Module: EfoNelfo::Properties::ClassMethods
- Defined in:
- lib/efo_nelfo/properties.rb
Instance Method Summary collapse
-
#properties ⇒ Object
Returns all properties defined for the class.
-
#property(name, options = {}) ⇒ Object
Creates an attribute with given name.
Instance Method Details
#properties ⇒ Object
Returns all properties defined for the class
76 77 78 |
# File 'lib/efo_nelfo/properties.rb', line 76 def properties @_properties ||= {} end |
#property(name, options = {}) ⇒ Object
Creates an attribute with given name.
Options
- type String, Integer etc. Default is String
- required whether attribute is required. Default is false
- limit Length the attribute can be. Default is nil
- alias Norwegian alias name for the attribute
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/efo_nelfo/properties.rb', line 51 def property(name, ={}) = { type: :string, required: false, }.update name = name.to_sym alias_name = .delete(:alias) # ensure all options are valid EfoNelfo::Property. # ensure property is unique raise EfoNelfo::DuplicateProperty if properties.has_key?(name) # setup getters and setters create_reader_for(name, ) create_setter_for(name, ) unless [:read_only] create_question_for(name) if [:type] == :boolean create_alias_for(name, alias_name, ) if alias_name properties[name] = end |