active_resource_inspector 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +46 -22
- data/active_resource_inspector.gemspec +3 -0
- data/lib/active_resource_inspector.rb +35 -39
- data/lib/active_resource_inspector/version.rb +1 -1
- data/lib/tasks/resources.rake +4 -4
- metadata +37 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 263c0bb7b2ba44879188cac903f0736c11f160ea
|
4
|
+
data.tar.gz: 25a87e4e343ebe709b7f3b1648ce493937d8c4c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48cb5dd0b57da36e33850cd0a239aa21db49e572c60f574cbb2f93faea034f3c606ea4f8263899295295045d586aa04f22d0c9af554b505906071375e4abe302
|
7
|
+
data.tar.gz: bca5207196a38f04d32679079974e86daf8a3377a50910bd0235584a978765236a93e1f498e8f83204f612e1b66661f1047f8862c86f883ea22ad3777bb95936
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,39 +1,63 @@
|
|
1
|
-
|
1
|
+
ActiveResource Inspector
|
2
|
+
========================
|
2
3
|
|
3
|
-
|
4
|
+
The gem provides ability to inspect ActiveResource files of any ruby project.
|
4
5
|
|
5
|
-
|
6
|
+
Using the `Rake` task, it prints results in format much like Rails's rake route does, but here it grouped by host and authentication type.
|
6
7
|
|
7
|
-
|
8
|
+
Case for Rails project:
|
9
|
+
-----------------------
|
8
10
|
|
9
|
-
|
11
|
+
For example in your Rails project you could have ActiveResource model like so:
|
10
12
|
|
11
|
-
```ruby
|
12
|
-
gem 'active_resource_inspector'
|
13
13
|
```
|
14
|
+
class Inventory < ActiveResource::Base
|
15
|
+
include ActiveResource::Singleton
|
16
|
+
self.site = 'http://example.com:3000'
|
17
|
+
self.prefix = '/products/:product_id/'
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
and you type within project folder:
|
14
22
|
|
15
|
-
|
23
|
+
```
|
24
|
+
rake resources:list
|
25
|
+
```
|
16
26
|
|
17
|
-
|
27
|
+
you will get:
|
18
28
|
|
19
|
-
|
29
|
+
```
|
30
|
+
~/you_rails_project$ rake resources:list
|
31
|
+
Location: /Users/tsyren/code/book_store/app/models
|
20
32
|
|
21
|
-
|
33
|
+
http://37s.sunrise.i:3000 (no auth)
|
34
|
+
/products/:product_id/inventories.json
|
35
|
+
```
|
22
36
|
|
23
|
-
|
37
|
+
Case for non-Rails project:
|
38
|
+
---------------------------
|
24
39
|
|
25
|
-
|
40
|
+
For non-Rails project you need to pass the path manually, for example you stored your active resource files in `./app/resources` folder then:
|
26
41
|
|
27
|
-
|
42
|
+
```
|
43
|
+
rake resources:list["./app/resources"]
|
44
|
+
```
|
28
45
|
|
29
|
-
|
46
|
+
and the result expected the same as above example.
|
30
47
|
|
31
|
-
|
48
|
+
Installation
|
49
|
+
------------
|
50
|
+
|
51
|
+
```
|
52
|
+
gem 'active_resource_inspector', group: :development
|
53
|
+
```
|
54
|
+
|
55
|
+
or
|
56
|
+
|
57
|
+
```
|
58
|
+
gem install active_resource_inspector
|
59
|
+
```
|
32
60
|
|
33
|
-
|
61
|
+
note: aims for development usage only.
|
34
62
|
|
35
|
-
|
36
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
-
5. Create a new Pull Request
|
63
|
+
Give try and drop me feedback.
|
@@ -19,6 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_runtime_dependency 'activesupport', '>= 4.0.0'
|
23
|
+
|
22
24
|
spec.add_development_dependency "bundler", "~> 1.9"
|
23
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "activeresource", '~> 4.0', '>= 4.0.0'
|
24
27
|
end
|
@@ -1,63 +1,48 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
1
2
|
require "active_resource_inspector/version"
|
2
3
|
require 'active_resource_inspector/railtie' if defined?(Rails::Railtie)
|
3
4
|
|
4
5
|
module ActiveResourceInspector
|
5
|
-
def self.run(type = nil)
|
6
|
-
Base.new.send(type || :short_print)
|
7
|
-
end
|
8
|
-
|
9
6
|
class Base
|
10
|
-
|
11
|
-
|
12
|
-
models = Dir[File.join(Rails.root,'app', 'models', '**/*.rb')].select{|res| res.match(/concerns/).nil? }
|
13
|
-
filtered_models = models.select do |res|
|
14
|
-
filename = File.basename(res, '.rb')
|
15
|
-
next if filename.downcase.match(/abstract/)
|
7
|
+
attr_reader :resources
|
8
|
+
attr_accessor :dirname
|
16
9
|
|
10
|
+
def resources
|
11
|
+
@resources ||= files.map do |file|
|
12
|
+
filename = file.split(dirname).last.gsub('.rb', '')
|
17
13
|
klass = filename.camelize.constantize
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
dir, _ = File.split(res)
|
22
|
-
filename = File.basename(res, '.rb')
|
23
|
-
basedir = dir.split('/').last
|
24
|
-
if 'models' == basedir
|
25
|
-
filename.camelize.constantize
|
14
|
+
next if klass.class == Module
|
15
|
+
if ActiveResource::Base == klass.superclass && klass.site.present?
|
16
|
+
klass
|
26
17
|
else
|
27
|
-
|
18
|
+
next
|
28
19
|
end
|
29
|
-
end
|
20
|
+
end.compact
|
30
21
|
end
|
31
22
|
|
32
|
-
def
|
33
|
-
|
23
|
+
def files
|
24
|
+
Dir[File.join(dirname, '**/*.rb')]
|
34
25
|
end
|
35
26
|
|
36
|
-
def
|
37
|
-
defaul_print
|
38
|
-
["\t"*5, res.prefix_source, res.collection_name, res.format_extension, " (", res, ") \n\n"].join('')
|
39
|
-
end
|
27
|
+
def self.print(dirpath)
|
28
|
+
factory(dirpath).defaul_print
|
40
29
|
end
|
41
30
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
def self.detailed_print
|
32
|
+
factory(dirpath).defaul_print do |res|
|
33
|
+
["\t"*5, res.prefix_source, res.collection_name, res.format_extension, " (", res, ") \n\n"].join('')
|
34
|
+
end
|
46
35
|
end
|
47
36
|
|
48
|
-
private
|
49
|
-
|
50
37
|
def defaul_print(&block)
|
51
|
-
puts "
|
52
|
-
puts "\nPrint ActiveResource entity's paths grouped by endpoint & auth type."
|
53
|
-
puts "\nLocation: #{@dirname}"
|
38
|
+
puts "Location: #{dirname}"
|
54
39
|
puts "\n"
|
55
|
-
|
40
|
+
resources.group_by{|e| e.site.to_s }.each do |endpoint, rs|
|
56
41
|
rs.group_by{|e| e.auth_type }.each do |auth_type, rs2|
|
57
42
|
if auth_type.nil?
|
58
|
-
puts "#{endpoint} #{rs2[0].headers.empty? ? '(no auth)' : '
|
43
|
+
puts "#{endpoint} #{rs2[0].headers.empty? ? '(no auth)' : 'with headers auth '+rs2[0].headers.to_s }"
|
59
44
|
else
|
60
|
-
puts "#{endpoint}
|
45
|
+
puts "#{endpoint} wiht auth #{auth_type.capitalize}"
|
61
46
|
end
|
62
47
|
t = rs2.map do |res|
|
63
48
|
if block_given?
|
@@ -68,7 +53,18 @@ module ActiveResourceInspector
|
|
68
53
|
end
|
69
54
|
puts t.sort
|
70
55
|
end
|
71
|
-
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def self.factory(dirname)
|
62
|
+
Base.new.tap do |obj|
|
63
|
+
if defined?(Rails::Railtie)
|
64
|
+
obj.dirname = File.join(Rails.root,'app', 'models')
|
65
|
+
else
|
66
|
+
obj.dirname = dirname || '.'
|
67
|
+
end
|
72
68
|
end
|
73
69
|
end
|
74
70
|
end
|
data/lib/tasks/resources.rake
CHANGED
@@ -2,11 +2,11 @@ require 'active_resource_inspector'
|
|
2
2
|
|
3
3
|
namespace :resources do
|
4
4
|
desc "Print ActiveResource entity's paths grouped by endpoint & auth type."
|
5
|
-
task list: :environment do
|
6
|
-
ActiveResourceInspector.
|
5
|
+
task :list, [:dirname] => :environment do |t, args|
|
6
|
+
ActiveResourceInspector::Base.print(args[:dirname])
|
7
7
|
end
|
8
|
-
task detailed_list: :environment do
|
9
|
-
ActiveResourceInspector.
|
8
|
+
task :detailed_list, [:dirname] => :environment do |t, args|
|
9
|
+
ActiveResourceInspector::Base.detailed_print(args[:dirname])
|
10
10
|
end
|
11
11
|
|
12
12
|
task :default => [:list]
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_resource_inspector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tsyren Ochirov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,26 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activeresource
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.0'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 4.0.0
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '4.0'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 4.0.0
|
41
75
|
description: Allows you to inpsect your project's ActiveResource entities.
|
42
76
|
email:
|
43
77
|
- nsu1team@gmail.com
|
@@ -53,6 +87,7 @@ files:
|
|
53
87
|
- LICENSE.txt
|
54
88
|
- README.md
|
55
89
|
- Rakefile
|
90
|
+
- active_resource_inspector-0.1.0.gem
|
56
91
|
- active_resource_inspector.gemspec
|
57
92
|
- bin/console
|
58
93
|
- bin/setup
|