Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #76 from st0012/refactor-configuration
Browse files Browse the repository at this point in the history
Implement Configuration class manually
  • Loading branch information
st0012 committed May 9, 2021
2 parents 8bfe981 + 7e49664 commit 033dc19
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/tapping_device.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
require "active_support/core_ext/module/introspection"
require "active_support/core_ext/object/blank"
require "method_source" # for using Method#source

require "tapping_device/version"
require "tapping_device/manageable"
require "tapping_device/payload"
require "tapping_device/output"
require "tapping_device/trackable"
require "tapping_device/configurable"
require "tapping_device/configuration"
require "tapping_device/exceptions"
require "tapping_device/method_hijacker"
require "tapping_device/trackers/initialization_tracker"
Expand All @@ -27,7 +28,6 @@ class TappingDevice

extend Manageable

include Configurable
include Output::Helpers

def initialize(options = {}, &block)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
require "active_support/configurable"
require "active_support/concern"

class TappingDevice
module Configurable
extend ActiveSupport::Concern

class Configuration
DEFAULTS = {
filter_by_paths: [],
exclude_by_paths: [],
Expand All @@ -16,12 +11,24 @@ module Configurable
only_private: false
}.merge(TappingDevice::Output::DEFAULT_OPTIONS)

included do
include ActiveSupport::Configurable
def initialize
@options = {}

DEFAULTS.each do |key, value|
config[key] = value
@options[key] = value
end
end

def [](key)
@options[key]
end

def []=(key, value)
@options[key] = value
end
end

def self.config
@config ||= Configuration.new
end
end
2 changes: 1 addition & 1 deletion spec/configurable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
around do |example|
example.run

TappingDevice::Configurable::DEFAULTS.each do |key, value|
TappingDevice::Configuration::DEFAULTS.each do |key, value|
TappingDevice.config[key] = value
end
end
Expand Down

0 comments on commit 033dc19

Please sign in to comment.