module ControllableVersioning::ClassMethods
Public Class Methods
extended(klass)
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 3 def self.extended(klass) klass.class_eval do @default = true @user_defined_column_hash = {} @excluded_columns = [] end end
Public Instance Methods
control_versioning() { || ... }
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 11 def control_versioning yield end
target_model()
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 15 def target_model @target_model end
versioned_column_hash()
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 19 def versioned_column_hash target_hash = {} target_hash.merge!(default_column_hash) if @default target_hash.merge!(@user_defined_column_hash) target_hash end
Private Instance Methods
default(is_default=true)
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 40 def default(is_default=true) @default = is_default end
default_column_hash()
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 27 def default_column_hash default_excluded_columns = %i(id created_at updated_at originated_model_id originated_model_name) columns = self.target_model.column_names.map(&:to_sym) - default_excluded_columns - @excluded_columns columns.map do |col| [col, col] end.to_h end
exclude(excluded_columns)
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 48 def exclude(excluded_columns) @excluded_columns = excluded_columns end
target(target_model)
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 36 def target(target_model) @target_model = target_model end
versioning_columns(target_hash)
click to toggle source
# File lib/controllable_versioning/class_methods.rb, line 44 def versioning_columns(target_hash) @user_defined_column_hash = target_hash if target_hash end