Module: Modelish::Configuration

Included in:
Modelish, Base
Defined in:
lib/modelish/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ignore_unknown_propertiesObject

If true, ignore unknown property names when initializing new models; otherwise, raise an error when an unknown property is encountered. Defaults to false.



6
7
8
# File 'lib/modelish/configuration.rb', line 6

def ignore_unknown_properties
  @ignore_unknown_properties
end

Class Method Details

.extended(base) ⇒ Object

When this module is extended, set all configuration options to their default values



25
26
27
# File 'lib/modelish/configuration.rb', line 25

def self.extended(base)
  base.reset
end

Instance Method Details

#configureObject

Configures this module through the given +block+. Default configuration options will be applied unless they are explicitly overridden in the +block+.

Examples:

Disable raising errors on unknown property names

Modelish.configure do |config|
  config.ignore_unknown_properties = true
end


37
38
39
40
41
42
43
# File 'lib/modelish/configuration.rb', line 37

def configure
  if block_given?
    yield self
  end

  self
end

#ignore_unknown_properties!Object

When set, unknown property names will be ignored during modelish initialization and property setting.

See Also:

  • {raise_errors_on_unknown_properties!}


12
13
14
# File 'lib/modelish/configuration.rb', line 12

def ignore_unknown_properties!
  self.ignore_unknown_properties = true
end

#raise_errors_on_unknown_properties!Object

When set, unknown property names will cause errors to be raised when encountered during modelish initialization and property setting. This is the default behavior.

See Also:

  • {ignore_unknown_properties!}


20
21
22
# File 'lib/modelish/configuration.rb', line 20

def raise_errors_on_unknown_properties!
  self.ignore_unknown_properties = false
end

#resetObject

Resets this module's configuration.



46
47
48
# File 'lib/modelish/configuration.rb', line 46

def reset
  self.ignore_unknown_properties = false
end