Module: Adva::Markup::ActiveRecord::ActMacro

Defined in:
lib/adva/markup/active_record.rb

Instance Method Summary collapse

Instance Method Details

#attribute_readers_module(attributes) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/adva/markup/active_record.rb', line 21

def attribute_readers_module(attributes)
  Module.new.tap do |readers|
    attributes.each do |name|
      readers.module_eval <<-rb
        def #{name}; read_filtered_attributes ? send(:#{name}_html) : super; end
      rb
    end
  end
end

#filters(*attributes) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/adva/markup/active_record.rb', line 5

def filters(*attributes)
  unless filters?
    class_inheritable_accessor :filtered_attributes
    class_inheritable_accessor :read_filtered_attributes

    self.filtered_attributes = []
    self.read_filtered_attributes = false

    before_save :filter_attributes!
    include InstanceMethods
  end

  self.filtered_attributes += attributes
  include attribute_readers_module(attributes)
end

#filters?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/adva/markup/active_record.rb', line 31

def filters?
  included_modules.include?(InstanceMethods)
end