Class: MagicUserstamp::Config::Pattern

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_name, column_name, options = nil) ⇒ Pattern

Returns a new instance of Pattern.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/magic_userstamp/config.rb', line 91

def initialize(event_name, column_name, options = nil)
  @event_name = event_name
  @column_name = column_name
  options = {
    :stampable_class_names => nil,
    :stamper_class_name => 'User',
    :stamper_attr_name => nil # sholuld not be only 'id' but PK column name
  }.update(options || {})
  @stampable_class_names = options.delete(:stampable_class_names)
  MagicUserstamp::Stampable.raise_unless_valid_options_for_stampable_on(options)
  @options_for_stampable_on = options
  @stamper_class_name = options[:stamper_class_name]
  @stamper_attr_name = options[:stamper_attr_name]
end

Instance Attribute Details

#column_nameObject (readonly)

Returns the value of attribute column_name.



87
88
89
# File 'lib/magic_userstamp/config.rb', line 87

def column_name
  @column_name
end

#event_nameObject (readonly)

Returns the value of attribute event_name.



87
88
89
# File 'lib/magic_userstamp/config.rb', line 87

def event_name
  @event_name
end

#options_for_stampable_onObject (readonly)

Returns the value of attribute options_for_stampable_on.



89
90
91
# File 'lib/magic_userstamp/config.rb', line 89

def options_for_stampable_on
  @options_for_stampable_on
end

#stampable_class_namesObject (readonly)

Returns the value of attribute stampable_class_names.



87
88
89
# File 'lib/magic_userstamp/config.rb', line 87

def stampable_class_names
  @stampable_class_names
end

#stamper_attr_nameObject (readonly)

Returns the value of attribute stamper_attr_name.



88
89
90
# File 'lib/magic_userstamp/config.rb', line 88

def stamper_attr_name
  @stamper_attr_name
end

#stamper_class_nameObject (readonly)

Returns the value of attribute stamper_class_name.



88
89
90
# File 'lib/magic_userstamp/config.rb', line 88

def stamper_class_name
  @stamper_class_name
end

Instance Method Details

#args_for_stampable_on(column_name = nil) ⇒ Object



111
112
113
# File 'lib/magic_userstamp/config.rb', line 111

def args_for_stampable_on(column_name = nil)
  [event_name, {:attribute => column_name || self.column_name}.update(@options_for_stampable_on)]
end

#stampable?(klass, column_name) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
109
# File 'lib/magic_userstamp/config.rb', line 106

def stampable?(klass, column_name)
  (stampable_class_names.nil? ? true : stampable_class_names.include?(klass.name)) &&
    (column_name.to_s == self.column_name.to_s)
end