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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f26698e3375411b125ae6b15b92a9c4f8118d93
4
- data.tar.gz: 0689b9e9fdacf7fc36b2fbdd94edad39b8afa7d1
3
+ metadata.gz: 9307de84fcbf48db7c625db8437689d8919db50a
4
+ data.tar.gz: 8f47e642fe877cfa8714e34f13767924d7a9001d
5
5
  SHA512:
6
- metadata.gz: 3d9aed53491c6b07f816f88f2a8ce4972d86ba35df42dc3da36f4a259948c54142f226b2332cca17608f0545499d6eac3d81e84064e9d2c63bcab5edd8445b61
7
- data.tar.gz: 4f1842b07056fa6660e2c41b2522d84c23ebc743053d179293a6c3baaccb8ce891f2b9cd5e86fb835d55bb258d0be0416c95880baeeea8eeb06abec03970aafd
6
+ metadata.gz: 605469a97a7fbcd66491e345b8aaf20731b5cd8c234eb676c47e4b82c38a32224a345a49ff510059d169e810137634e59f6a3a29701abd6a25439679f511ff17
7
+ data.tar.gz: 1bb08e9e3aef2dbd73c5035b3babece65d139d6b32c1cec3e80c6f5d37df6e548d1e298a5831a43c1d0d807f8090772bf5475b80bef5e856cfc6bdec8fd6459f
data/Changes ADDED
@@ -0,0 +1,6 @@
1
+ Go to https://github.com/hisaichi5518/ruby-ddp/issues for the roadmap and known issues.
2
+
3
+ 0.1.0 2014-12-16 07:29:33 UTC
4
+ - Added Ddp::Dumper
5
+ - Added Kernel.dp
6
+ - use dp and deprecated Ddp.dp and Ddp.dumper
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Ddp
2
2
 
3
- TOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO SIMPLE Data Printer
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
- Ddp.p({test: 1000})
13
- Ddp.p(Ddp.method(:dumper))
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: Ddp.dumper>
32
- source_location: ["/Users/hisaichi5518/projects/ddp/lib/ddp.rb", 8]
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
- puts dumper(obj)
7
+ deprecated "Ddp.p(...) is deprecated. use `dp(...)`."
8
+ dp obj
6
9
  end
7
10
 
8
11
  def self.dumper(obj)
9
- text = <<-EOF
10
- #{((obj.class.ancestors - obj.class.included_modules).join(" < "))} {
11
- included_modules:
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
- if obj.methods.include?(:source_location)
18
- text += " source_location: #{obj.source_location || "(Opps! this is a C method.)"}\n"
19
- end
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
@@ -0,0 +1,7 @@
1
+ require "ddp/dumper"
2
+
3
+ module Kernel
4
+ def dp(*val)
5
+ puts Ddp::Dumper.dump(*val)
6
+ end
7
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Ddp
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'ddp/core_ext/kernel'
3
+
4
+ describe Kernel do
5
+ it "imported dp" do
6
+ expect(Kernel.method(:dp).name).to eq :dp
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'ddp/dumper'
3
+
4
+ describe Ddp::Dumper do
5
+ describe ".dump" do
6
+ it "return dumped" do
7
+ result = Ddp::Dumper.dump({test: "test"}, {test: "hoge"}, ["hoge", 100])
8
+ expect(result.class).to eq String
9
+ end
10
+ end
11
+ end
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.1
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-05 00:00:00.000000000 Z
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