darko 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4811d58ebc63ef9dd14b764131e95ffa9487445e8715fff764b7c297017fc2f5
4
+ data.tar.gz: 2fae7e1a75b8a5399ad99d50e6ad8548f67779b3a977656b5cb3815bf3ca1726
5
+ SHA512:
6
+ metadata.gz: e582f791ae350bca78b46050fe6ecdbad2e380fa42c11e04e95729798e898399e76f9634b9353ff10a5e34b67c3d563486805b6bf65a6e7364efe38623827ade
7
+ data.tar.gz: a7fbfaa1b2acddee76eb210f7e3b2236335861e5c901686f13c2d0dde22ef605a1c4d4afb983f44e4e22a48363c55015988a801ef8e13257fb1dbe6115f2b656
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ Darko
@@ -0,0 +1 @@
1
+ ruby-2.5.5
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at donniepropst@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in Darko.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ darko (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (12.3.3)
11
+ rspec (3.9.0)
12
+ rspec-core (~> 3.9.0)
13
+ rspec-expectations (~> 3.9.0)
14
+ rspec-mocks (~> 3.9.0)
15
+ rspec-core (3.9.1)
16
+ rspec-support (~> 3.9.1)
17
+ rspec-expectations (3.9.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.9.0)
20
+ rspec-mocks (3.9.1)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.9.0)
23
+ rspec-support (3.9.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ darko!
30
+ rake (~> 12.0)
31
+ rspec (~> 3.0)
32
+
33
+ BUNDLED WITH
34
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Donnie Propst
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,80 @@
1
+ # Darko
2
+
3
+ ## 28:06:42:12
4
+
5
+ Darko helps you debug. A great use case for Darko is if you want to know *exactly* when a piece of data is accessed or mutated. This enables you to quickly get to the bottom of _where_ something is happening.
6
+
7
+ Just like Frank without the bunny suit.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'darko'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install darko
24
+
25
+ ## Usage
26
+
27
+ This is a super simple example with watching an instance of class `Foo`
28
+
29
+ ```ruby
30
+ require 'darko'
31
+ # Some class with something you aren't sure why is changing
32
+ class Foo
33
+ attr_accessor :data
34
+ def initialize data
35
+ @data = data
36
+ end
37
+ end
38
+
39
+ an_object = Foo.new('data')
40
+ frank = Darko::Watcher.new(an_object, :@data)
41
+ frank.enable! # this will start the object spy
42
+ foo.data << 'add some data'
43
+
44
+ frank.disable! # this will quit spying and put everything back to normal :)
45
+ ```
46
+
47
+ ```ruby
48
+ # You can log darko data to files too
49
+ frank = Darko::Watcher.new(an_object, :@data, true).enable!
50
+
51
+ ```
52
+
53
+ ## TODO
54
+ - Darko::Configuration class
55
+ - figure out how to follow object reassignment
56
+ - watch objects, not only object attributes
57
+ - allow watchers on method call
58
+ - stats about access
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/prodion23/darko. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/prodion23/darko/blob/master/CODE_OF_CONDUCT.md).
69
+
70
+ All PR's are welcome :) - before merging you must provide test coverage of the feature. If you plan to do any extreme rewrites or redesigns please open an issue so we can talk about it.
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
76
+
77
+ ## Code of Conduct
78
+ TL;DR - Be nice to everyone
79
+
80
+ Everyone interacting in the Darko project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/Darko/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Darko"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require_relative 'lib/darko/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "darko"
5
+ spec.version = Darko::VERSION
6
+ spec.authors = ["Donnie Propst"]
7
+ spec.email = ["donniepropst@gmail.com"]
8
+
9
+ spec.summary = "A debugging assistant - figure out whats going on"
10
+ spec.description = "Darko allows you to spy on objects"
11
+ spec.homepage = "https://github.com/prodion23/darko"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/prodion23/darko"
19
+ spec.metadata["changelog_uri"] = "https://github.com/prodion23/darko"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ end
@@ -0,0 +1,6 @@
1
+ module Darko
2
+ class Error < StandardError; end
3
+ end
4
+ require_relative './darko/version'
5
+ require_relative './darko/watcher'
6
+ require_relative './darko/delegator'
@@ -0,0 +1,38 @@
1
+ require 'logger'
2
+
3
+ module Darko
4
+ class Delegator < SimpleDelegator
5
+
6
+ def initialize object, log_to_file
7
+ @initialized = false
8
+ @log_to_file = log_to_file
9
+ @logger = log_to_file ? Logger.new(File.new("#{object.class}-#{Time.now.to_i}.darko.log", "w")) : Logger.new(STDOUT)
10
+ super(object)
11
+ @initialized = true
12
+ @logger.debug('Darko delegator initialized')
13
+ end
14
+
15
+ alias_method :darko__getobj__, :__getobj__
16
+ # TODO: Differentiate between access and mutation - this should be a filter passed through the watcher init
17
+ def __getobj__
18
+ called(:access) if @initialized # not fan
19
+ darko__getobj__
20
+ end
21
+
22
+ def __setobj__ new_obj
23
+ called(:mutation) if @initialized # not fan
24
+ super(new_obj)
25
+ end
26
+
27
+ # Anything we want to do on watcher object access do it here
28
+ def called action_type
29
+ begin
30
+ stack_without_darko = Kernel.caller(3..-1).join("\n")
31
+ @logger.debug("Object: #{action_type} detected at: ")
32
+ @logger.debug "\t#{stack_without_darko}"
33
+ rescue
34
+ @logger.error('Unable to collect a stack trace')
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Darko
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,48 @@
1
+ module Darko
2
+ class Watcher
3
+ attr_accessor :delegator
4
+ def initialize object, attribute=nil, log_to_file=false
5
+ @object = object
6
+ @attribute = attribute
7
+ @delegator = Darko::Delegator.new(attribute_target, log_to_file)
8
+ end
9
+
10
+ # Enabling the Darko::Watcher replaces the object with a Darko::Delegator to spy on mutations
11
+ def enable!
12
+ swap_in_delegator
13
+ end
14
+
15
+ # Disabling the Darko::Watcher will reset the object attribute to the original - removing the delegator
16
+ def disable!
17
+ swap_out_delegator
18
+ end
19
+
20
+ private
21
+
22
+ def swap_out_delegator
23
+ original_obj = @delegator.instance_variable_get(:@delegate_sd_obj)
24
+ @object.send(target_setter_message, @attribute, original_obj)
25
+ end
26
+
27
+ def swap_in_delegator
28
+ @object.send(target_setter_message, @attribute, @delegator)
29
+ end
30
+
31
+ def class_target?
32
+ @object.is_a?(Class) && @object.class_variables.include?(@attribute)
33
+ end
34
+
35
+ # Depending on if the target object is a class or instance changes what message we need to send,
36
+ # some memoization just to avoid if/elses - I'd like this to live elsewhere
37
+ def target_getter_message
38
+ @_target_getter_message ||= class_target? ? :class_variable_get : :instance_variable_get
39
+ end
40
+ def target_setter_message
41
+ @_target_setter_message ||= class_target? ? :class_variable_set : :instance_variable_set
42
+ end
43
+
44
+ def attribute_target
45
+ @object.send(target_getter_message, @attribute)
46
+ end
47
+ end
48
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: darko
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Donnie Propst
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Darko allows you to spy on objects
14
+ email:
15
+ - donniepropst@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - ".ruby-gemset"
23
+ - ".ruby-version"
24
+ - ".travis.yml"
25
+ - CODE_OF_CONDUCT.md
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - darko.gemspec
34
+ - lib/darko.rb
35
+ - lib/darko/delegator.rb
36
+ - lib/darko/version.rb
37
+ - lib/darko/watcher.rb
38
+ homepage: https://github.com/prodion23/darko
39
+ licenses:
40
+ - MIT
41
+ metadata:
42
+ allowed_push_host: https://rubygems.org
43
+ homepage_uri: https://github.com/prodion23/darko
44
+ source_code_uri: https://github.com/prodion23/darko
45
+ changelog_uri: https://github.com/prodion23/darko
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 2.7.6.2
63
+ signing_key:
64
+ specification_version: 4
65
+ summary: A debugging assistant - figure out whats going on
66
+ test_files: []