aniks_search 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/aniks_search.rb +114 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 436618eb6e75f937845978d640a892c11f0849d0
4
+ data.tar.gz: 05302e0361fb7dd8ff179a8d34d5671e381a503b
5
+ SHA512:
6
+ metadata.gz: 701845840935ee0ac423d4985ffa6d6bee7d8df83e43e5a67a03ccc2dec180937ffee85c569589b9fd2bf921dc86e16d0c861e96ce012c513966b49024726b35
7
+ data.tar.gz: c5f2ea64aaf5eac664738292a99fd4bff5c3630402dfb8b4db665ded2b5d1c0f48608567fd3e28207d09200ddfa991bade971591bedbf16f51f37d22c0d51fef
@@ -0,0 +1,114 @@
1
+ module Aniks
2
+ class AniksSearch
3
+
4
+ def self.content_search
5
+ query_string = params[:search_form][:search]
6
+ routing_path = get_routing_path
7
+ @api_response = HTTParty.get("https://cdn.contentful.com/spaces/jrlorqxrzseg/entries?access_token=8926a86933b23d4eebd718b4b7b988b661ececd448753a245b449f99440be972&query=#{query_string}")
8
+ search_pair = {}
9
+ JSON.parse(@api_response)['items'].each do |content|
10
+ search_pair[content['sys']['id']] = content['fields']
11
+ end
12
+ @path = []
13
+ search_pair.each do |id, fields|
14
+ formats = []
15
+ fields.each do |title, value|
16
+ if value.to_s.downcase.include? (query_string.downcase)
17
+ formats << "fields[:#{title}]"
18
+ end
19
+ end
20
+ formats.each do |format|
21
+ controller_array = controller_search(format, id)
22
+ view_array = views_search(format, controller_array)
23
+ routing_name = []
24
+ view_array.each do |a|
25
+ routing_method = ""
26
+ routing_method << a.split("/").last(2).first
27
+ routing_method << ","
28
+ routing_method << a.split("/").last.split(".").first
29
+ routing_name << routing_method
30
+ end
31
+ routing_name.each do |b|
32
+ if routing_path[b].present?
33
+ @path << routing_path[b]
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.get_routing_path
41
+ routing_path = {}
42
+ all_routes = Rails.application.routes.routes
43
+ routes = all_routes.collect do |route|
44
+ reqs = route.requirements.dup
45
+ reqs[:to] = route.app unless route.app.class.name.to_s =~ /^ActionDispatch::Routing/
46
+ reqs = reqs.empty? ? "" : reqs.inspect
47
+ {:name => route.name.to_s, :verb => route.verb.to_s, :path => route.path.spec.to_s, :controller => route.requirements[:controller], :action => route.requirements[:action]}
48
+ end
49
+ routes.each do |r|
50
+ if r[:path].exclude?("id")
51
+ routing_path["#{r[:controller]},#{r[:action]}"] = r[:name]
52
+ end
53
+ end
54
+ return routing_path
55
+ end
56
+
57
+ def self.static_search
58
+ view_array = []
59
+ query_string = params[:static_search_form][:search]
60
+ files = Dir["#{Rails.root}/app/views/**/*.html.erb"]
61
+ files.each do |textfile|
62
+ whole_file = File.foreach(textfile) do |line|
63
+ if line.include?(query_string)
64
+ view_array << textfile.split('/blog').last
65
+ end
66
+ end
67
+ end
68
+ routing_path = get_routing_path
69
+ routing_name = []
70
+ @path = []
71
+ view_array.each do |a|
72
+ routing_method = ""
73
+ routing_method << a.split("/").last(2).first
74
+ routing_method << ","
75
+ routing_method << a.split("/").last.split(".").first
76
+ routing_name << routing_method
77
+ end
78
+ routing_name.each do |b|
79
+ if routing_path[b].present?
80
+ @path << routing_path[b]
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.controller_search(format, id)
86
+ controller_array = []
87
+ controller_files = Dir["#{Rails.root}/app/controllers/**/*.rb"]
88
+ controller_files.each do |controllerfile|
89
+ hole_file = File.foreach(controllerfile) do |line|
90
+ if line.include?(id)
91
+ controller_array << line.gsub(/\s+/, "").partition(" ").first.split("=").first
92
+ end
93
+ end
94
+ end
95
+ return controller_array
96
+ end
97
+
98
+ def self.views_search(format, controller_array)
99
+ view_array = []
100
+ controller_array.each do |var|
101
+ files = Dir["#{Rails.root}/app/views/**/*.html.erb"]
102
+ files.each do |textfile|
103
+ whole_file = File.foreach(textfile) do |line|
104
+ if line.include?("#{var}.#{format}")
105
+ view_array << textfile.split('/blog').last
106
+ end
107
+ end
108
+ end
109
+ end
110
+ return view_array
111
+ end
112
+
113
+ end
114
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aniks_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anurag Singh
8
+ - Nikhil Agarwal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-09-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: nikhil.agarwal0201@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/aniks_search.rb
21
+ homepage:
22
+ licenses: []
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: aniks_search is for contentful search as well as static search
44
+ test_files: []