Module: EventStoreClient::Extensions::OptionsExtension::ClassMethods

Defined in:
lib/event_store_client/extensions/options_extension.rb

Instance Method Summary collapse

Instance Method Details

#inherited(klass) ⇒ Object



57
58
59
60
# File 'lib/event_store_client/extensions/options_extension.rb', line 57

def inherited(klass)
  super
  klass.options = Set.new(options).freeze
end

#option(opt_name, &blk) ⇒ Symbol

Parameters:

  • opt_name (Symbol)

    option name

  • blk (Proc)

    provide define value using block. It will be later evaluated in the context of your object to determine the default value of the option

Returns:

  • (Symbol)


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/event_store_client/extensions/options_extension.rb', line 45

def option(opt_name, &blk)
  self.options = (options + Set.new([opt_name])).freeze
  attr_writer opt_name

  define_method opt_name do
    result = instance_variable_get(:"@#{opt_name}")
    return result if instance_variable_defined?(:"@#{opt_name}")

    instance_exec(&blk) if blk
  end
end