active_resource_inspector 0.1.0 → 0.2.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: 1fbc1df0aef73d8397d4a7122b8e3c3eae314573
4
- data.tar.gz: 1b274db93071e7ac9e2e56c55d99e7eb99170a45
3
+ metadata.gz: 263c0bb7b2ba44879188cac903f0736c11f160ea
4
+ data.tar.gz: 25a87e4e343ebe709b7f3b1648ce493937d8c4c4
5
5
  SHA512:
6
- metadata.gz: 3d69b4798b70f8bd49872484dc6ff2f535c614ca0ba9cd169e782a07bd6b88a4c5e05c31d15fa49f374fb192afa718f376c55927caa318cb03d4df5d84f9168b
7
- data.tar.gz: e182e8b0fcc257128075678adbba2fdc5d3483c2f9c6cd1f45f66dc88e7ce107d18d809304ad626dbd9f8535095c3baecbe1022cfd2a9dccc5dc2ed2cf143ac2
6
+ metadata.gz: 48cb5dd0b57da36e33850cd0a239aa21db49e572c60f574cbb2f93faea034f3c606ea4f8263899295295045d586aa04f22d0c9af554b505906071375e4abe302
7
+ data.tar.gz: bca5207196a38f04d32679079974e86daf8a3377a50910bd0235584a978765236a93e1f498e8f83204f612e1b66661f1047f8862c86f883ea22ad3777bb95936
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/README.md CHANGED
@@ -1,39 +1,63 @@
1
- # ActiveResourceInspector
1
+ ActiveResource Inspector
2
+ ========================
2
3
 
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/active_resource_inspector`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ The gem provides ability to inspect ActiveResource files of any ruby project.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
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
- ## Installation
8
+ Case for Rails project:
9
+ -----------------------
8
10
 
9
- Add this line to your application's Gemfile:
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
- And then execute:
23
+ ```
24
+ rake resources:list
25
+ ```
16
26
 
17
- $ bundle
27
+ you will get:
18
28
 
19
- Or install it yourself as:
29
+ ```
30
+ ~/you_rails_project$ rake resources:list
31
+ Location: /Users/tsyren/code/book_store/app/models
20
32
 
21
- $ gem install active_resource_inspector
33
+ http://37s.sunrise.i:3000 (no auth)
34
+ /products/:product_id/inventories.json
35
+ ```
22
36
 
23
- ## Usage
37
+ Case for non-Rails project:
38
+ ---------------------------
24
39
 
25
- TODO: Write usage instructions here
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
- ## Development
42
+ ```
43
+ rake resources:list["./app/resources"]
44
+ ```
28
45
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
46
+ and the result expected the same as above example.
30
47
 
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- ## Contributing
61
+ note: aims for development usage only.
34
62
 
35
- 1. Fork it ( https://github.com/[my-github-username]/active_resource_inspector/fork )
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
- def initialize
11
- @dirname = File.join(Rails.root,'app', 'models')
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
- ActiveResource::Base == klass.superclass
19
- end
20
- @resources = filtered_models.sort.map do |res|
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
- "#{basedir}/#{filename}".camelize.constantize
18
+ next
28
19
  end
29
- end
20
+ end.compact
30
21
  end
31
22
 
32
- def short_print
33
- defaul_print
23
+ def files
24
+ Dir[File.join(dirname, '**/*.rb')]
34
25
  end
35
26
 
36
- def detailed_print
37
- defaul_print do |res|
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 example_print
43
- # TO-DO:
44
- # set random numbers
45
- # /api/v1/shops/12/publishers/4.json
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 "\nActiveResource Introspection"
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
- @resources.group_by{|e| e.site.to_s }.each do |endpoint, rs|
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)' : 'via '+rs2[0].headers.to_s }"
43
+ puts "#{endpoint} #{rs2[0].headers.empty? ? '(no auth)' : 'with headers auth '+rs2[0].headers.to_s }"
59
44
  else
60
- puts "#{endpoint} via #{auth_type.capitalize}"
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
- puts '-'*120
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
@@ -1,3 +1,3 @@
1
1
  module ActiveResourceInspector
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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.run
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.run(:detailed_print)
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.1.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-27 00:00:00.000000000 Z
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