Class: MagicUserstamp::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/magic_userstamp/config.rb

Defined Under Namespace

Classes: Pattern

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



26
27
28
29
# File 'lib/magic_userstamp/config.rb', line 26

def initialize
  @patterns = []
  @with_destroy = defined?(Caboose::Acts::Paranoid)
end

Instance Attribute Details

#patternsObject (readonly)

Returns the value of attribute patterns.



22
23
24
# File 'lib/magic_userstamp/config.rb', line 22

def patterns
  @patterns
end

#verboseObject

Returns the value of attribute verbose.



24
25
26
# File 'lib/magic_userstamp/config.rb', line 24

def verbose
  @verbose
end

#with_destroyObject

Returns the value of attribute with_destroy.



23
24
25
# File 'lib/magic_userstamp/config.rb', line 23

def with_destroy
  @with_destroy
end

Class Method Details

.clearObject



17
18
19
# File 'lib/magic_userstamp/config.rb', line 17

def clear
  @instance = nil
end

.instanceObject



9
10
11
# File 'lib/magic_userstamp/config.rb', line 9

def instance
  @instance ||= Config.new
end

.setup(&block) ⇒ Object



13
14
15
# File 'lib/magic_userstamp/config.rb', line 13

def setup(&block)
  instance.setup(&block)
end

Instance Method Details

#compatibles(options = nil) ⇒ Object



52
53
54
55
56
# File 'lib/magic_userstamp/config.rb', line 52

def compatibles(options = nil)
  on(:create , :created_by, options)
  on(:update , :updated_by, options)
  on(:destroy, :deleted_by, options) if with_destroy
end

#defaults(options = nil) ⇒ Object



46
47
48
49
50
# File 'lib/magic_userstamp/config.rb', line 46

def defaults(options = nil)
  on(:create , :creator_id, options)
  on(:update , :updater_id, options)
  on(:destroy, :deleter_id, options) if with_destroy
end

#on(event_name, column_name, options = nil) ⇒ Object



40
41
42
43
44
# File 'lib/magic_userstamp/config.rb', line 40

def on(event_name, column_name, options = nil)
  result = Pattern.new(event_name, column_name, options)
  patterns << result
  result
end

#pattern_for(klass, column_name) ⇒ Object



36
37
38
# File 'lib/magic_userstamp/config.rb', line 36

def pattern_for(klass, column_name)
  patterns.detect{|pattern| pattern.stampable?(klass, column_name)}
end

#setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



31
32
33
34
# File 'lib/magic_userstamp/config.rb', line 31

def setup
  yield(self) if block_given?
  self
end

#verbose?(klass, column_name) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
# File 'lib/magic_userstamp/config.rb', line 58

def verbose?(klass, column_name)
  case verbose
  when Hash then
    verbose_match?(verbose, klass, column_name)
  when Array then
    verbose.any?{|setting| verbose_match?(setting, klass, column_name)}
  else
    !!verbose
  end
end