Class: WithoutScope::ActsAsRevisable::Options

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

Overview

This class provides for a flexible method of setting options and querying them. This is especially useful for giving users flexibility when using your plugin.

Instance Method Summary collapse

Constructor Details

#initialize(*options, &block) ⇒ Options

Returns a new instance of Options.



7
8
9
10
# File 'lib/acts_as_revisable/options.rb', line 7

def initialize(*options, &block)
  @options = options.extract_options!
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/acts_as_revisable/options.rb', line 12

def method_missing(key, *args)
  return (@options[key.to_s.gsub(/\?$/, '').to_sym].eql?(true)) if key.to_s.match(/\?$/)
  if args.blank?
    @options[key.to_sym]
  else
    @options[key.to_sym] = args.size == 1 ? args.first : args
  end
end