Class: MagicUserstamp::Config
- Inherits:
-
Object
- Object
- MagicUserstamp::Config
- Defined in:
- lib/magic_userstamp/config.rb
Defined Under Namespace
Classes: Pattern
Instance Attribute Summary collapse
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
-
#with_destroy ⇒ Object
Returns the value of attribute with_destroy.
Class Method Summary collapse
Instance Method Summary collapse
- #compatibles(options = nil) ⇒ Object
- #defaults(options = nil) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #on(event_name, column_name, options = nil) ⇒ Object
- #pattern_for(klass, column_name) ⇒ Object
- #setup {|_self| ... } ⇒ Object
- #verbose?(klass, column_name) ⇒ Boolean
Constructor Details
#initialize ⇒ Config
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
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
22 23 24 |
# File 'lib/magic_userstamp/config.rb', line 22 def patterns @patterns end |
#verbose ⇒ Object
Returns the value of attribute verbose.
24 25 26 |
# File 'lib/magic_userstamp/config.rb', line 24 def verbose @verbose end |
#with_destroy ⇒ Object
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
.clear ⇒ Object
17 18 19 |
# File 'lib/magic_userstamp/config.rb', line 17 def clear @instance = nil end |
.instance ⇒ Object
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( = nil) on(:create , :created_by, ) on(:update , :updated_by, ) on(:destroy, :deleted_by, ) if with_destroy end |
#defaults(options = nil) ⇒ Object
46 47 48 49 50 |
# File 'lib/magic_userstamp/config.rb', line 46 def defaults( = nil) on(:create , :creator_id, ) on(:update , :updater_id, ) on(:destroy, :deleter_id, ) 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, = nil) result = Pattern.new(event_name, column_name, ) 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
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
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 |