Module: HotLikeSauce::ClassMethods
- Defined in:
- lib/hot_like_sauce.rb
Instance Method Summary collapse
- #attr_obscurable(*args) ⇒ Object
- #obscure_read_on_fields!(*fields_array) ⇒ Object
- #obscured_fields ⇒ Object
- #obscured_fields=(val) ⇒ Object
- #unobscure_read_on_fields!(*fields_array) ⇒ Object
- #unobscured_read_fields ⇒ Object
- #unobscured_read_fields=(val) ⇒ Object
Instance Method Details
#attr_obscurable(*args) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hot_like_sauce.rb', line 50 def attr_obscurable(*args) fields = args.map {|arg| arg if arg.is_a?(Symbol)}.compact = args.map {|arg| arg if arg.is_a?(Hash)}.compact.first ||= {} fields.each do |field| type = self.columns_hash[field.to_s].type raise "#{field} must be a string or text field" unless type == :string || type == :text self.obscured_fields = (self.obscured_fields << field).uniq self.unobscured_read_fields = (self.unobscured_read_fields << field).uniq unless [:obscure_on_read] == true define_method field do super() value = read_attribute(field) self.class.unobscured_read_fields.include?(field) ? _unobscure(value) : value end define_method "#{field}=" do |value| super(value) write_attribute(field, _obscure(value)) end if [:unobscured_accessor] == true define_method "unobscured_#{field}" do _unobscure(read_attribute(field)) end end end end |
#obscure_read_on_fields!(*fields_array) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/hot_like_sauce.rb', line 83 def obscure_read_on_fields!(*fields_array) if fields_array.empty? self.unobscured_read_fields = [] else self.unobscured_read_fields -= fields_array end end |
#obscured_fields ⇒ Object
34 35 36 |
# File 'lib/hot_like_sauce.rb', line 34 def obscured_fields @obscured_fields ||= [] end |
#obscured_fields=(val) ⇒ Object
38 39 40 |
# File 'lib/hot_like_sauce.rb', line 38 def obscured_fields=(val) @obscured_fields = val end |
#unobscure_read_on_fields!(*fields_array) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/hot_like_sauce.rb', line 91 def unobscure_read_on_fields!(*fields_array) if fields_array.empty? self.unobscured_read_fields = self.obscured_fields else self.unobscured_read_fields += self.obscured_fields & fields_array end end |
#unobscured_read_fields ⇒ Object
42 43 44 |
# File 'lib/hot_like_sauce.rb', line 42 def unobscured_read_fields @unobscured_read_fields ||= [] end |
#unobscured_read_fields=(val) ⇒ Object
46 47 48 |
# File 'lib/hot_like_sauce.rb', line 46 def unobscured_read_fields=(val) @unobscured_read_fields = val end |