Class: ROM::Options::Option Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/support/options.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defines a single option

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Option

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Option.



45
46
47
48
49
50
51
52
# File 'lib/rom/support/options.rb', line 45

def initialize(name, options = {})
  @name = name
  @type = options.fetch(:type) { Object }
  @reader = options.fetch(:reader) { false }
  @allow = options.fetch(:allow) { [] }
  @default = options.fetch(:default) { Undefined }
  @ivar = :"@#{name}" if @reader
end

Instance Attribute Details

#allowObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/rom/support/options.rb', line 43

def allow
  @allow
end

#defaultObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/rom/support/options.rb', line 43

def default
  @default
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/rom/support/options.rb', line 43

def name
  @name
end

#typeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/rom/support/options.rb', line 43

def type
  @type
end

Instance Method Details

#allow?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


74
75
76
# File 'lib/rom/support/options.rb', line 74

def allow?(value)
  allow.empty? || allow.include?(value)
end

#assign_reader_value(object, value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
# File 'lib/rom/support/options.rb', line 58

def assign_reader_value(object, value)
  object.instance_variable_set(@ivar, value)
end

#default?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


62
63
64
# File 'lib/rom/support/options.rb', line 62

def default?
  @default != Undefined
end

#default_value(object) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'lib/rom/support/options.rb', line 66

def default_value(object)
  default.is_a?(Proc) ? default.call(object) : default
end

#reader?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


54
55
56
# File 'lib/rom/support/options.rb', line 54

def reader?
  @reader
end

#type_matches?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


70
71
72
# File 'lib/rom/support/options.rb', line 70

def type_matches?(value)
  value.is_a?(type)
end