show_code 0.1.0 → 0.1.1

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: b36d2729058722810f11824e6b5e418395fcf130
4
- data.tar.gz: e54c43af71a144a0f4f05f66fb9fcfe712726c03
3
+ metadata.gz: a58a7d68906360e8984066796e0b05ad3ac687ab
4
+ data.tar.gz: a2eace5e41bcc43550529d35cafe9a69209c0116
5
5
  SHA512:
6
- metadata.gz: 82b7e3bcb42f4b92286ba1c29b0825ce8cc9351513633770cbc9779f69c0c4a22bf1f38f84205a0c4bdb14ad02d818d11779cf893c50efb8c004df5a2e8ea32a
7
- data.tar.gz: c1c70ab90a9b655075aefc9bd4fc4c4a4fdda21019b9cb6241dd02d8266192c265e1f73e3f18002708211def940d100233322d174b103eed83fc10476d093b29
6
+ metadata.gz: de1028e128e1da58548ac64cbcde0251e2109bec25e02f4486b8bf7c72388fc971963953fb9bc6e44e90e7bc17fdd6171c534a9da19d11832abb38d1dc6686ad
7
+ data.tar.gz: 21b85e098479ebcef206a37eaa595557b12ddf7a694ed042d3dbd5f9e5a241080eb6f54de4b5105f566ee55dd0669022b01f871b18eab5037ba2e2982857c9ef
data/README.md CHANGED
@@ -1,41 +1,52 @@
1
- # ShowCode
1
+ ## Code Show ##
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/show_code`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ show_code provides a quick way to show ruby method source codes in terminal.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'show_code'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
5
+ __NOTE__: show_code current version *require* Ruby v1.9.0 or later.
20
6
 
7
+ ### Installation ###
8
+ # Installing as Ruby gem
21
9
  $ gem install show_code
22
10
 
23
- ## Usage
11
+ # Or in gemfile
12
+ $ gem show_code
24
13
 
25
- TODO: Write usage instructions here
14
+ ### Usage ###
15
+ You can use show_code in `console c` or `irb`
26
16
 
27
- ## Development
17
+ ```ruby
18
+ require "show_code" # just when irb
19
+ ShowCode method_object
20
+ # or
21
+ ShowCode method_string
22
+ ```
28
23
 
29
- 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.
24
+ ### Examples ###
30
25
 
31
- 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).
26
+ #### show code
27
+ ```ruby
28
+ ShowCode 'ShowCode::Code.new.greet'
32
29
 
33
- ## Contributing
30
+ # def greet
31
+ # puts 'Hello ShowCode!'
32
+ # end
33
+ # => #<UnboundMethod: ShowCode::Code#greet>
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/show_code. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
35
+ # also you can use this way, it does the same thing
36
+ ShowCode ShowCode::Code.instance_method(:greet)
36
37
 
38
+ ```
39
+ #### open resource file
40
+ Sometimes, we wanna open the resource file to edit, as default `geidt` will open the file.
37
41
 
38
- ## License
42
+ ```ruby
43
+ ShowCode.open 'ShowCode::Code.new.greet'
44
+ # or ShowCode.open ShowCode::Code.instance_method(:greet)
45
+ ```
39
46
 
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+ ### TODO ###
48
+ - Colorize output
49
+ - Add more statistic analysis in output
41
50
 
51
+ ### License ###
52
+ Released under the [MIT](http://opensource.org/licenses/MIT) license. See LICENSE file for details.
@@ -1,3 +1,3 @@
1
1
  module ShowCode
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/show_code.rb CHANGED
@@ -1,5 +1,33 @@
1
- require "show_code/version"
1
+ Dir[File.dirname(__FILE__) + "/show_code/*.rb"].each { |file| require(file) }
2
2
 
3
3
  module ShowCode
4
- # Your code goes here...
4
+
5
+ def self.parse(obj)
6
+ sol = SourceLocation.new obj
7
+ code = Code.new sol
8
+ puts code.content
9
+ sol.method
10
+ end
11
+
12
+ def self.open(obj)
13
+ sol = SourceLocation.new obj
14
+ file = sol.file
15
+ %x[gedit #{file}]
16
+ if $?.success?
17
+ 'File has opened via gedit!'
18
+ else
19
+ 'Sorry, cannot open the file.'
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ # ShowCode() runs like ShowCode.parse()
26
+ module Kernel
27
+
28
+ def ShowCode(target)
29
+ ShowCode.parse target
30
+ end
31
+ module_function :ShowCode
32
+
5
33
  end
data/show_code.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.bindir = "exe"
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
+ spec.required_ruby_version = '>= 1.9.0'
26
27
 
27
28
  spec.add_development_dependency "bundler", "~> 1.14"
28
29
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: show_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cenxky
@@ -84,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - ">="
86
86
  - !ruby/object:Gem::Version
87
- version: '0'
87
+ version: 1.9.0
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="