Class: ActsAsTable::ValueProvider::WrappedValue

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/acts_as_table/value_provider.rb

Overview

ActsAsTable wrapped value object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_provider, base = nil, source_value = nil, target_value = nil, **options) ⇒ ActsAsTable::ValueProvider::WrappedValue

Returns a new ActsAsTable wrapped value object.

Parameters:

  • value_provider (ActsAsTable::ValueProvider::InstanceMethods)
  • base (ActiveRecord::Base, nil) (defaults to: nil)
  • source_value (Object, nil) (defaults to: nil)
  • target_value (Object, nil) (defaults to: nil)
  • options (Hash<Symbol, Object>)

Options Hash (**options):

  • :changed (Boolean)
  • :default (Boolean)


69
70
71
72
73
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 69

def initialize(value_provider, base = nil, source_value = nil, target_value = nil, **options)
  options.assert_valid_keys(:changed, :default)

  @value_provider, @base, @source_value, @target_value, @options = value_provider, base, source_value, target_value, options.dup
end

Instance Attribute Details

#baseActiveRecord::Base? (readonly)

Returns the record for this ActsAsTable wrapped value object.

Returns:

  • (ActiveRecord::Base, nil)


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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 56

class WrappedValue
  attr_reader :value_provider, :base, :source_value, :target_value, :options

  # Returns a new ActsAsTable wrapped value object.
  #
  # @param [ActsAsTable::ValueProvider::InstanceMethods] value_provider
  # @param [ActiveRecord::Base, nil] base
  # @param [Object, nil] source_value
  # @param [Object, nil] target_value
  # @param [Hash<Symbol, Object>] options
  # @option options [Boolean] :changed
  # @option options [Boolean] :default
  # @return [ActsAsTable::ValueProvider::WrappedValue]
  def initialize(value_provider, base = nil, source_value = nil, target_value = nil, **options)
    options.assert_valid_keys(:changed, :default)

    @value_provider, @base, @source_value, @target_value, @options = value_provider, base, source_value, target_value, options.dup
  end

  # Sets the ':changed' option for this ActsAsTable wrapped value object to 'true'.
  #
  # @return [Boolean]
  def changed!
    @options[:changed] = true
  end

  # Returns 'true' if the value of this ActsAsTable wrapped value object has changed. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def changed?
    !!@options[:changed]
  end
  alias_method :changed, :changed?

  # Returns 'true' if the value of this ActsAsTable wrapped value object is the default value for the value provider. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def default?
    !!@options[:default]
  end
  alias_method :default, :default?
end

#optionsHash<Symbol, Object> (readonly)

Returns the options for this ActsAsTable wrapped value object.

Returns:

  • (Hash<Symbol, Object>)


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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 56

class WrappedValue
  attr_reader :value_provider, :base, :source_value, :target_value, :options

  # Returns a new ActsAsTable wrapped value object.
  #
  # @param [ActsAsTable::ValueProvider::InstanceMethods] value_provider
  # @param [ActiveRecord::Base, nil] base
  # @param [Object, nil] source_value
  # @param [Object, nil] target_value
  # @param [Hash<Symbol, Object>] options
  # @option options [Boolean] :changed
  # @option options [Boolean] :default
  # @return [ActsAsTable::ValueProvider::WrappedValue]
  def initialize(value_provider, base = nil, source_value = nil, target_value = nil, **options)
    options.assert_valid_keys(:changed, :default)

    @value_provider, @base, @source_value, @target_value, @options = value_provider, base, source_value, target_value, options.dup
  end

  # Sets the ':changed' option for this ActsAsTable wrapped value object to 'true'.
  #
  # @return [Boolean]
  def changed!
    @options[:changed] = true
  end

  # Returns 'true' if the value of this ActsAsTable wrapped value object has changed. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def changed?
    !!@options[:changed]
  end
  alias_method :changed, :changed?

  # Returns 'true' if the value of this ActsAsTable wrapped value object is the default value for the value provider. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def default?
    !!@options[:default]
  end
  alias_method :default, :default?
end

#source_valueObject? (readonly)

Returns the source value of this ActsAsTable wrapped value object.

Returns:

  • (Object, nil)


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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 56

class WrappedValue
  attr_reader :value_provider, :base, :source_value, :target_value, :options

  # Returns a new ActsAsTable wrapped value object.
  #
  # @param [ActsAsTable::ValueProvider::InstanceMethods] value_provider
  # @param [ActiveRecord::Base, nil] base
  # @param [Object, nil] source_value
  # @param [Object, nil] target_value
  # @param [Hash<Symbol, Object>] options
  # @option options [Boolean] :changed
  # @option options [Boolean] :default
  # @return [ActsAsTable::ValueProvider::WrappedValue]
  def initialize(value_provider, base = nil, source_value = nil, target_value = nil, **options)
    options.assert_valid_keys(:changed, :default)

    @value_provider, @base, @source_value, @target_value, @options = value_provider, base, source_value, target_value, options.dup
  end

  # Sets the ':changed' option for this ActsAsTable wrapped value object to 'true'.
  #
  # @return [Boolean]
  def changed!
    @options[:changed] = true
  end

  # Returns 'true' if the value of this ActsAsTable wrapped value object has changed. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def changed?
    !!@options[:changed]
  end
  alias_method :changed, :changed?

  # Returns 'true' if the value of this ActsAsTable wrapped value object is the default value for the value provider. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def default?
    !!@options[:default]
  end
  alias_method :default, :default?
end

#target_valueObject? (readonly)

Returns the target value of this ActsAsTable wrapped value object.

Returns:

  • (Object, nil)


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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 56

class WrappedValue
  attr_reader :value_provider, :base, :source_value, :target_value, :options

  # Returns a new ActsAsTable wrapped value object.
  #
  # @param [ActsAsTable::ValueProvider::InstanceMethods] value_provider
  # @param [ActiveRecord::Base, nil] base
  # @param [Object, nil] source_value
  # @param [Object, nil] target_value
  # @param [Hash<Symbol, Object>] options
  # @option options [Boolean] :changed
  # @option options [Boolean] :default
  # @return [ActsAsTable::ValueProvider::WrappedValue]
  def initialize(value_provider, base = nil, source_value = nil, target_value = nil, **options)
    options.assert_valid_keys(:changed, :default)

    @value_provider, @base, @source_value, @target_value, @options = value_provider, base, source_value, target_value, options.dup
  end

  # Sets the ':changed' option for this ActsAsTable wrapped value object to 'true'.
  #
  # @return [Boolean]
  def changed!
    @options[:changed] = true
  end

  # Returns 'true' if the value of this ActsAsTable wrapped value object has changed. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def changed?
    !!@options[:changed]
  end
  alias_method :changed, :changed?

  # Returns 'true' if the value of this ActsAsTable wrapped value object is the default value for the value provider. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def default?
    !!@options[:default]
  end
  alias_method :default, :default?
end

#value_providerActsAsTable::ValueProvider::InstanceMethods (readonly)

Returns the ActsAsTable value provider for this ActsAsTable wrapped value object.



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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 56

class WrappedValue
  attr_reader :value_provider, :base, :source_value, :target_value, :options

  # Returns a new ActsAsTable wrapped value object.
  #
  # @param [ActsAsTable::ValueProvider::InstanceMethods] value_provider
  # @param [ActiveRecord::Base, nil] base
  # @param [Object, nil] source_value
  # @param [Object, nil] target_value
  # @param [Hash<Symbol, Object>] options
  # @option options [Boolean] :changed
  # @option options [Boolean] :default
  # @return [ActsAsTable::ValueProvider::WrappedValue]
  def initialize(value_provider, base = nil, source_value = nil, target_value = nil, **options)
    options.assert_valid_keys(:changed, :default)

    @value_provider, @base, @source_value, @target_value, @options = value_provider, base, source_value, target_value, options.dup
  end

  # Sets the ':changed' option for this ActsAsTable wrapped value object to 'true'.
  #
  # @return [Boolean]
  def changed!
    @options[:changed] = true
  end

  # Returns 'true' if the value of this ActsAsTable wrapped value object has changed. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def changed?
    !!@options[:changed]
  end
  alias_method :changed, :changed?

  # Returns 'true' if the value of this ActsAsTable wrapped value object is the default value for the value provider. Otherwise, returns 'false'.
  #
  # @return [Boolean]
  def default?
    !!@options[:default]
  end
  alias_method :default, :default?
end

Instance Method Details

#changed!Boolean

Sets the ':changed' option for this ActsAsTable wrapped value object to 'true'.

Returns:

  • (Boolean)


78
79
80
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 78

def changed!
  @options[:changed] = true
end

#changed?Boolean Also known as: changed

Returns 'true' if the value of this ActsAsTable wrapped value object has changed. Otherwise, returns 'false'.

Returns:

  • (Boolean)


85
86
87
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 85

def changed?
  !!@options[:changed]
end

#default?Boolean Also known as: default

Returns 'true' if the value of this ActsAsTable wrapped value object is the default value for the value provider. Otherwise, returns 'false'.

Returns:

  • (Boolean)


93
94
95
# File 'app/models/concerns/acts_as_table/value_provider.rb', line 93

def default?
  !!@options[:default]
end