Module: Capcoauth::Config::Option

Included in:
Capcoauth::Config
Defined in:
lib/capcoauth/config.rb

Instance Method Summary collapse

Instance Method Details

#extended(base) ⇒ Object



62
63
64
# File 'lib/capcoauth/config.rb', line 62

def extended(base)
  base.send(:private, :option)
end

#option(name, options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/capcoauth/config.rb', line 40

def option(name, options = {})
  attribute = options[:as] || name

  Builder.instance_eval do
    define_method name do |*args, &block|
      value = block ? block : args.first

      @config.instance_variable_set(:"@#{attribute}", value)
    end
  end

  define_method attribute do |*args|
    if instance_variable_defined?(:"@#{attribute}")
      instance_variable_get(:"@#{attribute}")
    else
      options[:default]
    end
  end

  public attribute
end