Top Level Namespace
Defined Under Namespace
Modules: Visibilize, VisibilizeGenerator
Instance Method Summary collapse
Instance Method Details
#visibilize(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/visibilize.rb', line 6 def visibilize(={}) column = [:column] || :visible_id callback = [:callback] || :before_create type = [:type] || :integer unique = [:unique] || true length = [:length] || 8 lamb = [:lambda] || nil # Define a method to fill the column with appropiate value method_name="visibilize_#{column}" define_method(method_name) do raise "Visibilize Error: Attribute #{column} not found in #{self.class.name} instance." unless self.has_attribute?(column) # Values are generated by VisibilizeGenerator class value=lamb ? lamb.call : VisibilizeGenerator.get_value_for(type, self.class, column, length, unique) write_attribute(column, value) end # Create a callback to execute method callback=callback.to_s.split('_') set_callback callback[1].to_sym, callback[0].to_sym, method_name.to_sym end |