Module: VShipping::Configuration::ClassMethods

Defined in:
lib/v_shipping/configuration.rb

Instance Method Summary collapse

Instance Method Details

#add_config(name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/v_shipping/configuration.rb', line 14

def add_config(name)
  class_eval "    @\#{name} = nil\n    def self.\#{name}(value=nil)\n      @\#{name} = value if value\n      return @\#{name} if self.object_id == \#{self.object_id} || defined?(@\#{name})\n      name = superclass.\#{name}\n      return nil if name.nil? && !instance_variable_defined?(:@\#{name})\n      @\#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name\n    end\n    def self.\#{name}=(value)\n      @\#{name} = value\n    end\n    def \#{name}=(value)\n      @\#{name} = value\n    end\n    def \#{name}\n      value = @\#{name} if instance_variable_defined?(:@\#{name})\n      value = self.class.\#{name} unless instance_variable_defined?(:@\#{name})\n      if value.instance_of?(Proc)\n        value.arity >= 1 ? value.call(self) : value.call\n      else\n        value\n      end\n    end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

#add_deprecated_config(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/v_shipping/configuration.rb', line 42

def add_deprecated_config(name)
  class_eval "    def self.\#{name}(value=nil)\n      ActiveSupport::Deprecation.warn \"#\#{name} is deprecated and has no effect\"\n    end\n    def self.\#{name}=(value)\n      ActiveSupport::Deprecation.warn \"#\#{name} is deprecated and has no effect\"\n    end\n    def \#{name}=(value)\n      ActiveSupport::Deprecation.warn \"#\#{name} is deprecated and has no effect\"\n    end\n    def \#{name}\n      ActiveSupport::Deprecation.warn \"#\#{name} is deprecated and has no effect\"\n    end\n  RUBY\nend\n", __FILE__, __LINE__ + 1

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



59
60
61
# File 'lib/v_shipping/configuration.rb', line 59

def configure
  yield self
end

#reset_configObject

sets configuration back to default



66
67
68
69
70
71
# File 'lib/v_shipping/configuration.rb', line 66

def reset_config
  configure do |config|
    config.ahamove_api_key = nil
    config.ahamove_config_path = nil
  end
end