ddp 0.0.1 → 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.
- checksums.yaml +4 -4
- data/Changes +6 -0
- data/README.md +34 -6
- data/lib/ddp.rb +10 -12
- data/lib/ddp/core_ext/kernel.rb +7 -0
- data/lib/ddp/dumper.rb +56 -0
- data/lib/ddp/version.rb +1 -1
- data/spec/ddp/core_ext/kernel_spec.rb +8 -0
- data/spec/ddp/dumper_spec.rb +11 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9307de84fcbf48db7c625db8437689d8919db50a
|
4
|
+
data.tar.gz: 8f47e642fe877cfa8714e34f13767924d7a9001d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 605469a97a7fbcd66491e345b8aaf20731b5cd8c234eb676c47e4b82c38a32224a345a49ff510059d169e810137634e59f6a3a29701abd6a25439679f511ff17
|
7
|
+
data.tar.gz: 1bb08e9e3aef2dbd73c5035b3babece65d139d6b32c1cec3e80c6f5d37df6e548d1e298a5831a43c1d0d807f8090772bf5475b80bef5e856cfc6bdec8fd6459f
|
data/Changes
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Ddp
|
2
2
|
|
3
|
-
|
3
|
+
Too Simple Data Printer.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
@@ -9,27 +9,55 @@ Write ruby script:
|
|
9
9
|
```ruby
|
10
10
|
require "ddp"
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
class TestModule
|
13
|
+
def piyo
|
14
|
+
# ...
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
dp %w[100 101 102]
|
19
|
+
dp test: 1000
|
20
|
+
dp TestModule.method(:instance_method)
|
21
|
+
dp TestModule.instance_method(:piyo)
|
14
22
|
```
|
15
23
|
|
16
24
|
Run ruby script:
|
17
25
|
|
18
26
|
```shell
|
19
|
-
$ ruby -Ilib test.rb
|
27
|
+
$ ruby -Ilib test.rb
|
28
|
+
Array < Object < BasicObject {
|
29
|
+
included_modules:
|
30
|
+
Enumerable
|
31
|
+
Kernel
|
32
|
+
inspect:
|
33
|
+
["100", "101", "102"]
|
34
|
+
source_location:
|
35
|
+
There is no source_location.
|
36
|
+
}
|
20
37
|
Hash < Object < BasicObject {
|
21
38
|
included_modules:
|
22
39
|
Enumerable
|
23
40
|
Kernel
|
24
41
|
inspect:
|
25
42
|
{:test=>1000}
|
43
|
+
source_location:
|
44
|
+
There is no source_location.
|
26
45
|
}
|
27
46
|
Method < Object < BasicObject {
|
28
47
|
included_modules:
|
29
48
|
Kernel
|
30
49
|
inspect:
|
31
|
-
#<Method:
|
32
|
-
source_location:
|
50
|
+
#<Method: Class(Module)#instance_method>
|
51
|
+
source_location:
|
52
|
+
This is C method.
|
53
|
+
}
|
54
|
+
UnboundMethod < Object < BasicObject {
|
55
|
+
included_modules:
|
56
|
+
Kernel
|
57
|
+
inspect:
|
58
|
+
#<UnboundMethod: TestModule#piyo>
|
59
|
+
source_location:
|
60
|
+
["test.rb", 4]
|
33
61
|
}
|
34
62
|
```
|
35
63
|
|
data/lib/ddp.rb
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
require "ddp/version"
|
2
|
+
require "ddp/core_ext/kernel"
|
3
|
+
require "ddp/dumper"
|
2
4
|
|
3
5
|
module Ddp
|
4
6
|
def self.p(obj)
|
5
|
-
|
7
|
+
deprecated "Ddp.p(...) is deprecated. use `dp(...)`."
|
8
|
+
dp obj
|
6
9
|
end
|
7
10
|
|
8
11
|
def self.dumper(obj)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#{obj.class.included_modules.join("\n ")}
|
13
|
-
inspect:
|
14
|
-
#{obj.inspect}
|
15
|
-
EOF
|
12
|
+
deprecated "Ddp.dumper(...) is deprecated. use `dp(...)`."
|
13
|
+
dp obj
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
text += "}"
|
16
|
+
private
|
17
|
+
def self.deprecated(text)
|
18
|
+
warn text + "this method will remove 0.1.5 and this gem version is #{VERSION}"
|
21
19
|
end
|
22
20
|
end
|
data/lib/ddp/dumper.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Ddp
|
2
|
+
class Dumper
|
3
|
+
def self.dump(*val)
|
4
|
+
new(*val).dump
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_accessor :objects
|
8
|
+
def initialize(*val)
|
9
|
+
@objects = val
|
10
|
+
end
|
11
|
+
|
12
|
+
def dump
|
13
|
+
objects.map do |obj|
|
14
|
+
strip <<-EOF
|
15
|
+
#{fetch_ancestors_without_included_modules_by(obj).join(" < ")} {
|
16
|
+
included_modules:
|
17
|
+
#{join_included_modules_for(obj, 12)}
|
18
|
+
inspect:
|
19
|
+
#{inspect_for(obj)}
|
20
|
+
source_location:
|
21
|
+
#{fetch_source_location(obj)}
|
22
|
+
}
|
23
|
+
EOF
|
24
|
+
end.join()
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def fetch_ancestors_without_included_modules_by(obj)
|
29
|
+
obj.class.ancestors - obj.class.included_modules
|
30
|
+
end
|
31
|
+
|
32
|
+
def join_included_modules_for(obj, indent)
|
33
|
+
obj.class.included_modules.join($/ + " " * indent)
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect_for(obj)
|
37
|
+
obj.inspect
|
38
|
+
end
|
39
|
+
|
40
|
+
def fetch_source_location(obj)
|
41
|
+
return "There is no source_location." if !obj.respond_to?(:source_location)
|
42
|
+
sl = obj.source_location
|
43
|
+
if sl.nil?
|
44
|
+
return "This is C method."
|
45
|
+
end
|
46
|
+
sl.inspect
|
47
|
+
end
|
48
|
+
|
49
|
+
def strip(text)
|
50
|
+
indent = text.scan(/^[ \t]*(?=\S)/).min
|
51
|
+
size = 0
|
52
|
+
size = indent.size if indent
|
53
|
+
text.gsub(/^[ \t]{#{size}}/, '')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/ddp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ddp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hisaichi5518
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,13 +62,18 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
64
|
- ".travis.yml"
|
65
|
+
- Changes
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
68
69
|
- Rakefile
|
69
70
|
- ddp.gemspec
|
70
71
|
- lib/ddp.rb
|
72
|
+
- lib/ddp/core_ext/kernel.rb
|
73
|
+
- lib/ddp/dumper.rb
|
71
74
|
- lib/ddp/version.rb
|
75
|
+
- spec/ddp/core_ext/kernel_spec.rb
|
76
|
+
- spec/ddp/dumper_spec.rb
|
72
77
|
- spec/ddp_spec.rb
|
73
78
|
- spec/spec_helper.rb
|
74
79
|
homepage: https://github.com/hisaichi5518/ruby-ddp
|
@@ -96,5 +101,7 @@ signing_key:
|
|
96
101
|
specification_version: 4
|
97
102
|
summary: too simple data printer
|
98
103
|
test_files:
|
104
|
+
- spec/ddp/core_ext/kernel_spec.rb
|
105
|
+
- spec/ddp/dumper_spec.rb
|
99
106
|
- spec/ddp_spec.rb
|
100
107
|
- spec/spec_helper.rb
|