Module: NCore::Attributes::ClassMethods
- Defined in:
- lib/ncore/attributes.rb
Instance Method Summary collapse
Instance Method Details
#attr(*attrs) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/ncore/attributes.rb', line 11 def attr(*attrs) attrs.each do |attr| class_eval " def \#{attr}\n self[:\#{attr}]\n end\n AR\n end\nend\n", __FILE__, __LINE__+1 |
#attr_datetime(*attrs) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ncore/attributes.rb', line 21 def attr_datetime(*attrs) attrs.each do |attr| class_eval " def \#{attr}\n case self[:\#{attr}]\n when String\n Time.parse(self[:\#{attr}]).utc\n when Numeric\n Time.at(self[:\#{attr}]).utc\n else\n self[:\#{attr}]\n end\n rescue ArgumentError, TypeError\n self[:\#{attr}]\n end\n AD\n end\nend\n", __FILE__, __LINE__+1 |
#attr_decimal(*attrs) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ncore/attributes.rb', line 40 def attr_decimal(*attrs) attrs.each do |attr| class_eval " def \#{attr}\n case self[:\#{attr}]\n when String\n BigMoney.new(self[:\#{attr}])\n else\n self[:\#{attr}]\n end\n end\n AD\n end\nend\n", __FILE__, __LINE__+1 |