Module: GIGO::ActiveRecord::Base
- Defined in:
- lib/gigo/active_record/base.rb
Defined Under Namespace
Classes: GigoCoder
Instance Method Summary collapse
- #after_initialize_gigoize_attributes ⇒ Object
- #gigo_coder_for(klass) ⇒ Object
- #gigo_column(*attrs) ⇒ Object
- #gigo_columns(*excepts) ⇒ Object
Instance Method Details
#after_initialize_gigoize_attributes ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/gigo/active_record/base.rb', line 32 def after_initialize_gigoize_attributes after_initialize :gigoize_attributes define_method :gigoize_attributes do self.class.const_get(:GIGOColumns).instance_methods.each { |name| self.send(name) } end private :gigoize_attributes end |
#gigo_coder_for(klass) ⇒ Object
40 41 42 |
# File 'lib/gigo/active_record/base.rb', line 40 def gigo_coder_for(klass) GigoCoder.new(klass) end |
#gigo_column(*attrs) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gigo/active_record/base.rb', line 4 def gigo_column(*attrs) mod = begin if const_defined?(:GIGOColumns) const_get(:GIGOColumns) else m = const_set(:GIGOColumns, Module.new) include m m end end attrs.each do |attr| mod.module_eval <<-CODE, __FILE__, __LINE__ def #{attr} begin GIGO.load(super) rescue NoMethodError, ActiveModel::MissingAttributeError nil end end CODE end end |
#gigo_columns(*excepts) ⇒ Object
27 28 29 30 |
# File 'lib/gigo/active_record/base.rb', line 27 def gigo_columns(*excepts) cols = columns.select{ |c| c.type == :string || c.type == :text }.map{ |c| c.name.to_s } - excepts.map(&:to_s) gigo_column(*cols) end |