sexp_info 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3bd8f82aa90eba808eabde7302f2030462df7757
4
+ data.tar.gz: d3311b73d1c0bc5892cc670cfcd70223bf075ddd
5
+ SHA512:
6
+ metadata.gz: 686b50130c78bb0d5a246283a1297bf8317e40eba43b6eb06782e0f36f8bd74770972730b140fc5a0502fc21823d181e4b78e4bdbd645518f3df061106fad90a
7
+ data.tar.gz: 23b78fc01e4303c28f08f29c83f0d82215b9a02ceeec93d27541deebb9c873ec00ae05155e58235fe080f7f988f03b66ddc7681e631777e05e45df3f7c102df1
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *~
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color --format nested
data/.rvmrc ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 2.0.0" > .rvmrc
9
+ environment_id="ruby-2.0.0-p195@sexp_info"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.20.12 (stable)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: \E[32m$GEM_HOME\E[0m" # show the user the ruby and gemset they are using in green
37
+ else printf "%b" "Using: $GEM_HOME" # don't use colors in non-interactive shells
38
+ fi
39
+ fi
40
+ else
41
+ # If the environment file has not yet been created, use the RVM CLI to select.
42
+ rvm --create use "$environment_id" || {
43
+ echo "Failed to create RVM environment '${environment_id}'."
44
+ return 1
45
+ }
46
+ fi
47
+
48
+ # If you use bundler, this might be useful to you:
49
+ # if [[ -s Gemfile ]] && {
50
+ # ! builtin command -v bundle >/dev/null ||
51
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
52
+ # }
53
+ # then
54
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
55
+ # gem install bundler
56
+ # fi
57
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
58
+ # then
59
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
60
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sexp_info.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 svs
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # SexpInfo
2
+
3
+ This gem provides nice information about your program based on Ripper sexps. Given a ruby source file called foo.rb
4
+
5
+ ```ruby
6
+ class Foo
7
+ def bar(baz, quux = 123)
8
+ "yikes"
9
+ end
10
+ end
11
+ ```
12
+
13
+ we can do the folliwng
14
+
15
+ ```ruby
16
+ rip = Ripper.sexp(File.read('foo.rb'))
17
+ si = SexpInfo.new(rip)
18
+ si.defined_methods # => ["bar"]
19
+ si["bar"].arity # => 2
20
+ si["bar"].args[1].optional? # => true
21
+ ```
22
+
23
+ Please check the specs for more information
24
+
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ gem 'sexp_info'
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install sexp_info
39
+
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/sexp_info.rb ADDED
@@ -0,0 +1,37 @@
1
+ require "sexp_info/version"
2
+ require 'active_support/all'
3
+ require 'sexp_info/sexp_thing/sexp_thing'
4
+ class SexpInfo
5
+
6
+ def initialize(sexp)
7
+ @sexp = sexp
8
+ end
9
+
10
+ def type
11
+ sexp[1][0][0]
12
+ end
13
+
14
+ def defined_methods
15
+ defined(:def)
16
+ end
17
+
18
+ def defined_classes
19
+ defined(:class)
20
+ end
21
+
22
+ def defined_modules
23
+ defined(:module)
24
+ end
25
+
26
+ def [](name)
27
+ (defined_classes + defined_methods + defined_modules).find{|m| m == name }
28
+ end
29
+
30
+ private
31
+
32
+ attr_reader :sexp
33
+ def defined(type)
34
+ sexp[1] ? sexp[1].find_all{|s| s[0] == type}.map{|c| "SexpThing::#{type.to_s.camelize}".constantize.new(c) } : []
35
+ end
36
+
37
+ end
@@ -0,0 +1,15 @@
1
+ module SexpThing
2
+
3
+ class Arg < Base
4
+
5
+ def name
6
+ sexp[1]
7
+ end
8
+
9
+ def optional?
10
+ sexp.count == 2
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,31 @@
1
+ module SexpThing
2
+
3
+ class Args < Base
4
+
5
+ def [](index)
6
+ args[index]
7
+ end
8
+
9
+ def count
10
+ args.count
11
+ end
12
+
13
+ private
14
+
15
+ def args
16
+ arg_list + optional_args_list
17
+ end
18
+
19
+ def arg_list
20
+ return (sexp[1] ? [Arg.new(sexp[1])] : []) if sexp[0] == :params
21
+ (sexp[0] == :paren ? sexp[1][1] : sexp[1]).map{|a| Arg.new(a) }
22
+ end
23
+
24
+ def optional_args_list
25
+ as = (sexp[0] == :paren ? sexp[1][2] : sexp[2])
26
+ as ? as.map{|a| Arg.new(a) } : []
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,14 @@
1
+ module SexpThing
2
+
3
+ class Class < Base
4
+
5
+ def name
6
+ sexp[1][1][1]
7
+ end
8
+
9
+ def defined_methods
10
+ SexpInfo.new(sexp[3]).defined_methods
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,17 @@
1
+ module SexpThing
2
+ class Def < Base
3
+
4
+ def name
5
+ sexp[1][1]
6
+ end
7
+
8
+ def arity
9
+ args.count
10
+ end
11
+
12
+ def args
13
+ Args.new(sexp[2])
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module SexpThing
2
+
3
+ class Module < Base
4
+ def name
5
+ sexp[1][1][1]
6
+ end
7
+ def defined_classes
8
+ SexpInfo.new(sexp[2]).defined_classes
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,20 @@
1
+ module SexpThing
2
+
3
+ class Base
4
+ def initialize(sexp)
5
+ @sexp = sexp
6
+ end
7
+
8
+ def ==(other)
9
+ other.is_a?(String) ? name == other : self.sexp == other.sexp
10
+ end
11
+
12
+ attr_reader :sexp
13
+
14
+ end
15
+
16
+ end
17
+
18
+ ['args','arg','class','module','def'].each do |m|
19
+ require_relative m
20
+ end
@@ -0,0 +1,3 @@
1
+ class SexpInfo
2
+ VERSION = "0.0.1"
3
+ end
data/sexp_info.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sexp_info/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sexp_info"
8
+ spec.version = SexpInfo::VERSION
9
+ spec.authors = ["svs"]
10
+ spec.email = ["svs@svs.io"]
11
+ spec.description = %q{Peek under the hood of sexps}
12
+ spec.summary = %q{gracefully}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "active_support"
22
+ spec.add_dependency "i18n"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "rspec-given"
28
+ spec.add_development_dependency "awesome_print"
29
+ spec.add_development_dependency "pry_debug"
30
+ end
@@ -0,0 +1,15 @@
1
+ class StdClass
2
+
3
+
4
+ def optional_args(foo, bar = 123)
5
+ bar - 12
6
+ end
7
+
8
+ end
9
+
10
+ class OtherClass
11
+
12
+ def foo
13
+ end
14
+
15
+ end
@@ -0,0 +1,20 @@
1
+ def no_args
2
+ "no args"
3
+ end
4
+
5
+
6
+ def one_arg_no_parens foo
7
+ foo
8
+ end
9
+
10
+ def one_arg_parens(foo)
11
+ foo
12
+ end
13
+
14
+ def two_args(foo, bar)
15
+ foo || bar
16
+ end
17
+
18
+ def optional_args(foo, bar = 123)
19
+ bar - 12
20
+ end
@@ -0,0 +1,11 @@
1
+ module StdModule
2
+
3
+ class StdClass
4
+
5
+ def optional_args(foo, bar = 123)
6
+ bar - 12
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'awesome_print'
3
+ describe SexpInfo do
4
+
5
+ context "methods only" do
6
+ Given(:methods) { File.read('spec/fixtures/methods.rb') }
7
+ Given(:rip) { Ripper.sexp(methods) }
8
+ Given(:sexp) { SexpInfo.new(rip) }
9
+ Then { sexp.type.should == :def }
10
+ Then { sexp.defined_methods.should == ["no_args", "one_arg_no_parens", "one_arg_parens" ,"two_args", "optional_args"] }
11
+ Then { sexp["no_args"].arity.should == 0 }
12
+ Then { sexp["one_arg_no_parens"].arity.should == 1 }
13
+ Then { sexp["one_arg_parens"].arity.should == 1 }
14
+ Then { sexp["two_args"].arity.should == 2 }
15
+ Then { sexp["two_args"].args[0].should_not be_optional }
16
+ Then { sexp["optional_args"].args[1].should be_optional }
17
+ end
18
+
19
+
20
+ context "classes" do
21
+ Given(:classes) { File.read('spec/fixtures/classes.rb') }
22
+ Given(:rip) { Ripper.sexp(classes) }
23
+ Given(:sexp) { SexpInfo.new(rip) }
24
+ Then { sexp.defined_classes.should == ["StdClass", "OtherClass"] }
25
+ Then { sexp["StdClass"].defined_methods.should == ["optional_args"] }
26
+ end
27
+
28
+ context "classes" do
29
+ Given(:modules) { File.read('spec/fixtures/modules.rb') }
30
+ Given(:rip) { Ripper.sexp(modules) }
31
+ Given(:sexp) { SexpInfo.new(rip) }
32
+ Then { sexp.type.should == :module }
33
+ Then { sexp.defined_modules.should == ["StdModule"] }
34
+ Then { sexp["StdModule"].should be_a SexpThing::Module }
35
+ Then { sexp["StdModule"].defined_classes.should == ["StdClass"] }
36
+ end
37
+
38
+
39
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'rspec-given'
3
+
4
+ require 'sexp_info'
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sexp_info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - svs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: active_support
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-given
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: awesome_print
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry_debug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Peek under the hood of sexps
126
+ email:
127
+ - svs@svs.io
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .rvmrc
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - lib/sexp_info.rb
140
+ - lib/sexp_info/sexp_thing/arg.rb
141
+ - lib/sexp_info/sexp_thing/args.rb
142
+ - lib/sexp_info/sexp_thing/class.rb
143
+ - lib/sexp_info/sexp_thing/def.rb
144
+ - lib/sexp_info/sexp_thing/module.rb
145
+ - lib/sexp_info/sexp_thing/sexp_thing.rb
146
+ - lib/sexp_info/version.rb
147
+ - sexp_info.gemspec
148
+ - spec/fixtures/classes.rb
149
+ - spec/fixtures/methods.rb
150
+ - spec/fixtures/methods.rb~
151
+ - spec/fixtures/modules.rb
152
+ - spec/lib/sexp_info_spec.rb
153
+ - spec/spec_helper.rb
154
+ homepage: ''
155
+ licenses:
156
+ - MIT
157
+ metadata: {}
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ required_rubygems_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ requirements: []
173
+ rubyforge_project:
174
+ rubygems_version: 2.1.5
175
+ signing_key:
176
+ specification_version: 4
177
+ summary: gracefully
178
+ test_files:
179
+ - spec/fixtures/classes.rb
180
+ - spec/fixtures/methods.rb
181
+ - spec/fixtures/methods.rb~
182
+ - spec/fixtures/modules.rb
183
+ - spec/lib/sexp_info_spec.rb
184
+ - spec/spec_helper.rb