dev_suite 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92f5e3450bc8b204f0be7e25db8a863ebd49d4d5a6990cfad7c6d336ccaf7e5e
4
- data.tar.gz: 368e6bd01867d4fc92856b8bc4825e1e5bdc2b3b978e3afa0966139f59216f28
3
+ metadata.gz: 76f0e8870b8fe2bb1c8af41e541bd09f792662f49c1a869d5ddcf5fd4ae94584
4
+ data.tar.gz: 17a921feedc29e07133ce357fbb3b37ecd15800cd30f4fd3087d62f4a810970d
5
5
  SHA512:
6
- metadata.gz: 973f1f20d18eab20229c5df12a304c1370ccbfc56175795c9e55fc6bc2680c0a3a3adae63472bcd3dc15ed964ba4413a5847a55d8fefc28312a119af9b0b91d5
7
- data.tar.gz: f31d767559b8cd4fbfa961cafef17a5cbbcda42a78ee5e012147a96a2652fd8b3417e1184a1e5a60925032aa21b6d256902753c799c322aa48e5240016b6f901
6
+ metadata.gz: a32bb7865ee17f49b639d687950cfafeecc51df0dc9e2e7a7ef62018ea185fd522081f8c7b70c0346d0b77ec4d119030c7e9464cf38f4928dad11ee756baa01a
7
+ data.tar.gz: 668586bdbd2339888ef486a5e2fb424aa0f3532d8fa80e27f92f569e59506b2237852683725560e55109eb93c5af63d51e6333aceea5dcb018604574733be5ef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_suite (0.1.3)
4
+ dev_suite (0.2.0)
5
5
  benchmark (~> 0.1)
6
6
  get_process_mem (~> 0.2)
7
7
 
data/README.md CHANGED
@@ -51,7 +51,7 @@ DevSuite::SomeUtility.do_something
51
51
  ```ruby
52
52
  require 'dev_suite'
53
53
 
54
- DevSuite::Performance::Analyzer.analyze(description: "My Code Block") do
54
+ DevSuite::Performance.analyze(description: "My Code Block") do
55
55
  sum = 0
56
56
  1_000_000.times do |i|
57
57
  sum += i
@@ -93,7 +93,7 @@ DevSuite::SomeUtility.do_something
93
93
  base_path = "/path/to/your/directory"
94
94
 
95
95
  # Perform the visualization
96
- DevSuite::DirectoryTree::Visualizer.visualize(base_path)
96
+ DevSuite::DirectoryTree.visualize(base_path)
97
97
  ```
98
98
 
99
99
  **Example output**
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevSuite
4
+ module DirectoryTree
5
+ class Config
6
+ attr_reader :renderer
7
+
8
+ def initialize(renderer: :simple)
9
+ @renderer = Renderer.create(renderer)
10
+ freeze # Make the instance of this class immutable as well
11
+ end
12
+
13
+ class << self
14
+ #
15
+ # Provide global access to a single instance of Config
16
+ #
17
+ def configuration
18
+ @configuration ||= new
19
+ end
20
+
21
+ #
22
+ # Allow block-based configuration
23
+ #
24
+ def configure
25
+ yield(configuration)
26
+ rescue StandardError => e
27
+ handle_configuration_error(e)
28
+ raise
29
+ end
30
+
31
+ private
32
+
33
+ def handle_configuration_error(error)
34
+ puts "Configuration error: #{error.message}"
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "base"
4
-
5
3
  module DevSuite
6
4
  module DirectoryTree
7
5
  module Node
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "base"
4
-
5
3
  module DevSuite
6
4
  module DirectoryTree
7
5
  module Node
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "base"
4
-
5
3
  module DevSuite
6
4
  module DirectoryTree
7
5
  module Node
@@ -3,6 +3,7 @@
3
3
  module DevSuite
4
4
  module DirectoryTree
5
5
  module Node
6
+ require_relative "node/base"
6
7
  require_relative "node/file"
7
8
  require_relative "node/directory"
8
9
  require_relative "node/permission_denied"
@@ -6,17 +6,24 @@ module DevSuite
6
6
  module DirectoryTree
7
7
  module Renderer
8
8
  class Base
9
- def initialize(base_path)
10
- @base_path = Pathname.new(base_path)
11
- end
9
+ def render(path)
10
+ raise ArgumentError, "Invalid path" unless valid_path?(path)
12
11
 
13
- def render
14
- root = build_tree(@base_path)
12
+ root = build_tree(Pathname.new(path))
15
13
  render_node(root, "", true)
16
14
  end
17
15
 
18
16
  private
19
17
 
18
+ def valid_path?(path)
19
+ [
20
+ path.is_a?(String),
21
+ ::File.exist?(path),
22
+ ::File.directory?(path),
23
+ ::File.readable?(path),
24
+ ].all?
25
+ end
26
+
20
27
  # Builds the tree structure
21
28
  # @param path [Pathname] The path to build the tree from
22
29
  # @return [Node::Base] The root node of the tree
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "base"
4
- require_relative "../node"
5
-
6
3
  module DevSuite
7
4
  module DirectoryTree
8
5
  module Renderer
@@ -3,7 +3,19 @@
3
3
  module DevSuite
4
4
  module DirectoryTree
5
5
  module Renderer
6
+ require_relative "renderer/base"
6
7
  require_relative "renderer/simple"
8
+
9
+ class << self
10
+ def create(type)
11
+ case type
12
+ when :simple
13
+ Simple.new
14
+ else
15
+ raise ArgumentError, "Unknown renderer type: #{type}"
16
+ end
17
+ end
18
+ end
7
19
  end
8
20
  end
9
21
  end
@@ -1,25 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "pathname"
4
- require_relative "renderer"
5
4
 
6
5
  module DevSuite
7
6
  module DirectoryTree
8
7
  class Visualizer
9
- class << self
10
- # Visualizes the directory tree
11
- # @param base_path [String] The base path of the directory
12
- def visualize(base_path)
13
- new(base_path).visualize
14
- end
8
+ attr_reader :config
9
+
10
+ def initialize(config = Config.configuration)
11
+ @config = config
15
12
  end
16
13
 
17
- def initialize(base_path, renderer: Renderer::Simple.new(base_path))
18
- @renderer = renderer
14
+ # Visualizes the directory tree
15
+ # @param path [String] The base path of the directory
16
+ def visualize(path)
17
+ puts @config.renderer.render(path)
19
18
  end
19
+ end
20
20
 
21
- def visualize
22
- puts @renderer.render
21
+ class << self
22
+ def visualize(path)
23
+ visualizer = Visualizer.new
24
+ visualizer.visualize(path)
23
25
  end
24
26
  end
25
27
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module DevSuite
4
4
  module DirectoryTree
5
+ require_relative "directory_tree/node"
6
+ require_relative "directory_tree/renderer"
5
7
  require_relative "directory_tree/visualizer"
8
+ require_relative "directory_tree/config"
6
9
  end
7
10
  end
@@ -1,23 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "reportor"
4
- require_relative "profiler"
5
-
6
3
  module DevSuite
7
4
  module Performance
8
5
  class Analyzer
9
- class << self
10
- # Generates a performance report
11
- # @param benchmark_result [Benchmark::Tms] The benchmark result
12
- # @param memory_stats [Hash] The memory statistics
13
- def analyze(description: "Block", &block)
14
- raise ArgumentError, "No block given" unless block_given?
15
-
16
- analyzer = new(description: description)
17
- analyzer.analyze(&block)
18
- end
19
- end
20
-
21
6
  def initialize(description: "Block")
22
7
  @description = description
23
8
  @benchmark_profiler = Profiler::Benchmark.new
@@ -29,6 +14,8 @@ module DevSuite
29
14
  # @param block [Proc] The block to be analyzed
30
15
  # @raise [ArgumentError] If no block is given
31
16
  def analyze(&block)
17
+ raise ArgumentError, "No block given" unless block_given?
18
+
32
19
  memory_before = @memory_usage.current
33
20
  benchmark_result = profile_benchmark(&block)
34
21
  memory_after = @memory_usage.current
@@ -61,5 +48,12 @@ module DevSuite
61
48
  reportor.generate
62
49
  end
63
50
  end
51
+
52
+ class << self
53
+ def analyze(description: "Block", &block)
54
+ analyzer = Analyzer.new(description: description)
55
+ analyzer.analyze(&block)
56
+ end
57
+ end
64
58
  end
65
59
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "benchmark"
4
- require_relative "base"
5
4
 
6
5
  module DevSuite
7
6
  module Performance
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "base"
4
- require_relative "../data/memory_usage"
5
-
6
3
  module DevSuite
7
4
  module Performance
8
5
  module Profiler
@@ -3,6 +3,7 @@
3
3
  module DevSuite
4
4
  module Performance
5
5
  module Profiler
6
+ require_relative "profiler/base"
6
7
  require_relative "profiler/benchmark"
7
8
  require_relative "profiler/memory"
8
9
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "base"
4
-
5
3
  module DevSuite
6
4
  module Performance
7
5
  module Reportor
@@ -3,6 +3,7 @@
3
3
  module DevSuite
4
4
  module Performance
5
5
  module Reporting
6
+ require_relative "reportor/base"
6
7
  require_relative "reportor/simple"
7
8
  end
8
9
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module DevSuite
4
4
  module Performance
5
+ require_relative "performance/data"
6
+ require_relative "performance/profiler"
7
+ require_relative "performance/reportor"
5
8
  require_relative "performance/analyzer"
6
9
  end
7
10
  end
@@ -3,12 +3,6 @@
3
3
  module DevSuite
4
4
  module Utils
5
5
  module Color
6
- class << self
7
- def colorize(text, **kargs)
8
- Colorizer.new(Config.configuration).colorize(text, **kargs)
9
- end
10
- end
11
-
12
6
  class Colorizer
13
7
  attr_reader :config
14
8
 
@@ -20,6 +14,15 @@ module DevSuite
20
14
  puts @config.strategy.colorize(text, **kargs)
21
15
  end
22
16
  end
17
+
18
+ class << self
19
+ def colorize(text, **kargs)
20
+ raise ArgumentError, "Text to colorize must be a string" unless text.is_a?(String)
21
+
22
+ colorizer = Colorizer.new
23
+ colorizer.colorize(text, **kargs)
24
+ end
25
+ end
23
26
  end
24
27
  end
25
28
  end
@@ -1,3 +1,3 @@
1
1
  module DevSuite
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_suite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Nguyen
@@ -62,6 +62,7 @@ files:
62
62
  - dev_suite.gemspec
63
63
  - lib/dev_suite.rb
64
64
  - lib/dev_suite/directory_tree.rb
65
+ - lib/dev_suite/directory_tree/config.rb
65
66
  - lib/dev_suite/directory_tree/node.rb
66
67
  - lib/dev_suite/directory_tree/node/base.rb
67
68
  - lib/dev_suite/directory_tree/node/directory.rb