railstank 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
14
+
15
+ gem "indextank", ">= 1.0.9.1"
@@ -0,0 +1,42 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.5)
5
+ diff-lcs (1.1.2)
6
+ faraday (0.6.1)
7
+ addressable (~> 2.2.4)
8
+ multipart-post (~> 1.1.0)
9
+ rack (>= 1.1.0, < 2)
10
+ faraday-stack (0.1.0)
11
+ faraday (~> 0.6)
12
+ git (1.2.5)
13
+ indextank (1.0.9.1)
14
+ faraday-stack
15
+ yajl-ruby (>= 0.7.7)
16
+ jeweler (1.5.2)
17
+ bundler (~> 1.0.0)
18
+ git (>= 1.2.5)
19
+ rake
20
+ multipart-post (1.1.0)
21
+ rack (1.2.2)
22
+ rake (0.8.7)
23
+ rcov (0.9.9)
24
+ rspec (2.3.0)
25
+ rspec-core (~> 2.3.0)
26
+ rspec-expectations (~> 2.3.0)
27
+ rspec-mocks (~> 2.3.0)
28
+ rspec-core (2.3.1)
29
+ rspec-expectations (2.3.0)
30
+ diff-lcs (~> 1.1.2)
31
+ rspec-mocks (2.3.0)
32
+ yajl-ruby (0.8.2)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bundler (~> 1.0.0)
39
+ indextank (>= 1.0.9.1)
40
+ jeweler (~> 1.5.2)
41
+ rcov
42
+ rspec (~> 2.3.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 xdite
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ h1. Railstank
2
+
3
+ Rails plugin for IndexTank
4
+
5
+ h2. Install
6
+
7
+ <pre><code>gem install railstank</code></pre>
8
+
9
+ h2. Example
10
+
11
+ 1. Run generator
12
+ <pre><code>rails g railstank </code></pre>
13
+
14
+ It will automate generate indextank.yml to your config/ directory. Please fill up your information.*
15
+
16
+ *2. Include Railstank::Search in your model
17
+
18
+ <pre>
19
+ <code>
20
+ class Topic < ActiveRecord::Base
21
+ include Railstank::Search
22
+ has_indextank :forum_topic_index, :index_class_name => "Topic"
23
+ end
24
+ </code>
25
+ </pre>
26
+
27
+ * If you don't choose index_class_name, it will auto fetch your current class_name.
28
+ * Use :index_class_name, you can avoid STI class problem
29
+
30
+ h2. Contributing to Railstank
31
+
32
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
33
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
34
+ * Fork the project
35
+ * Start a feature/bugfix branch
36
+ * Commit and push until you are happy with your contribution
37
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
38
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
39
+
40
+ h2. Copyright
41
+
42
+ Copyright (c) 2011 xdite(xuite.joke@gmail.com) See LICENSE.txt for
43
+ further details.
44
+
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "railstank"
16
+ gem.homepage = "http://github.com/xdite/railstank"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{indextank rails plugin}
19
+ gem.description = %Q{indextank rails plugin}
20
+ gem.email = "xuite.joke@gmail.com"
21
+ gem.authors = ["xdite"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ gem.add_runtime_dependency 'indextank'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "railstank #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
File without changes
@@ -0,0 +1,11 @@
1
+ require 'rails/generators/base'
2
+
3
+ class RailstankGenerator < Rails::Generators::Base
4
+ def self.source_root
5
+ @source_root ||= File.expand_path('../templates', __FILE__)
6
+ end
7
+
8
+ def copy_config_file
9
+ copy_file "indextank.yml.example", "config/indextank.yml.example"
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ development: &DEV
2
+ api_url: "your api key"
3
+
4
+ test:
5
+ <<: *DEV
6
+
7
+ staging:
8
+ api_url: "your api key"
9
+
10
+ production:
11
+ api_url: "your api key"
12
+
@@ -0,0 +1,3 @@
1
+ SEARCH_API = IndexTank::Client.new Railstank.config["api_url"]
2
+ SEARCH_TOPIC_INDEX = SEARCH_API.indexes 'forum_topic_index'
3
+ SEARCH_USER_INDEX = SEARCH_API.indexes 'forum_user_index'
@@ -0,0 +1,60 @@
1
+ module Railstank
2
+
3
+ class Error < StandardError; end
4
+
5
+ def self.config(environment=RAILS_ENV)
6
+ @config ||= {}
7
+ @config[environment] ||= YAML.load(File.open(RAILS_ROOT + '/config/indextank.yml').read)[environment]
8
+ end
9
+
10
+ def self.client
11
+ @client = IndexTank::Client.new config["api_url"]
12
+ end
13
+
14
+ module Search
15
+ extend ActiveSupport::Concern
16
+ included do
17
+
18
+ end
19
+
20
+ module ClassMethods
21
+ attr_accessor :index_name, :search_index
22
+
23
+ def has_indextank(class_index_name,options={})
24
+ indextank_index_name = class_index_name.to_s
25
+
26
+ define_method "index_name" do
27
+ indextank_index_name
28
+ end
29
+ define_method "search_index" do
30
+ Railstank.client.indexes indextank_index_name
31
+ end
32
+
33
+ define_method "index_class_name" do
34
+ options[:index_class_name].present? ? options[:index_class_name].to_s.underscore : self.class.name.underscore
35
+ end
36
+
37
+ @index_name = indextank_index_name
38
+ @search_index = Railstank.client.indexes indextank_index_name
39
+ end
40
+
41
+ def isearch(field,options={})
42
+ fetch_id_type = options[:fetch]
43
+ results = search_index.search(field,options)["results"]
44
+ result_ids = results.map{ |result| result[fetch_id_type] }.uniq
45
+ end
46
+ end
47
+
48
+ module InstanceMethods
49
+ def add_to_search_index(content_hash)
50
+ search_index.document("#{index_class_name}_#{self.id}").add(content_hash)
51
+ end
52
+
53
+ def delete_index
54
+ search_index.document("#{index_class_name}_#{self.id}").delete
55
+ end
56
+
57
+ protected
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,74 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{railstank}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["xdite"]
12
+ s.date = %q{2011-04-28}
13
+ s.description = %q{indextank rails plugin}
14
+ s.email = %q{xuite.joke@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.textile",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/generators/railstank/USAGE",
29
+ "lib/generators/railstank/railstank_generator.rb",
30
+ "lib/generators/railstank/templates/indextank.yml.example",
31
+ "lib/generators/railstank/templates/load_indextank.rb",
32
+ "lib/railstank.rb",
33
+ "railstank.gemspec",
34
+ "spec/railstank_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/xdite/railstank}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.5.2}
41
+ s.summary = %q{indextank rails plugin}
42
+ s.test_files = [
43
+ "spec/railstank_spec.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ s.specification_version = 3
49
+
50
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<indextank>, [">= 1.0.9.1"])
52
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
53
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
55
+ s.add_development_dependency(%q<rcov>, [">= 0"])
56
+ s.add_runtime_dependency(%q<indextank>, [">= 0"])
57
+ else
58
+ s.add_dependency(%q<indextank>, [">= 1.0.9.1"])
59
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<indextank>, [">= 0"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<indextank>, [">= 1.0.9.1"])
67
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ s.add_dependency(%q<indextank>, [">= 0"])
72
+ end
73
+ end
74
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Railstank" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'railstank'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: railstank
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - xdite
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-28 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: indextank
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 121
29
+ segments:
30
+ - 1
31
+ - 0
32
+ - 9
33
+ - 1
34
+ version: 1.0.9.1
35
+ prerelease: false
36
+ type: :runtime
37
+ requirement: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 0
50
+ version: 2.3.0
51
+ prerelease: false
52
+ type: :development
53
+ requirement: *id002
54
+ - !ruby/object:Gem::Dependency
55
+ name: bundler
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 23
62
+ segments:
63
+ - 1
64
+ - 0
65
+ - 0
66
+ version: 1.0.0
67
+ prerelease: false
68
+ type: :development
69
+ requirement: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: jeweler
72
+ version_requirements: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 7
78
+ segments:
79
+ - 1
80
+ - 5
81
+ - 2
82
+ version: 1.5.2
83
+ prerelease: false
84
+ type: :development
85
+ requirement: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: rcov
88
+ version_requirements: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ prerelease: false
98
+ type: :development
99
+ requirement: *id005
100
+ - !ruby/object:Gem::Dependency
101
+ name: indextank
102
+ version_requirements: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ prerelease: false
112
+ type: :runtime
113
+ requirement: *id006
114
+ description: indextank rails plugin
115
+ email: xuite.joke@gmail.com
116
+ executables: []
117
+
118
+ extensions: []
119
+
120
+ extra_rdoc_files:
121
+ - LICENSE.txt
122
+ - README.textile
123
+ files:
124
+ - .document
125
+ - .rspec
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - README.textile
130
+ - Rakefile
131
+ - VERSION
132
+ - lib/generators/railstank/USAGE
133
+ - lib/generators/railstank/railstank_generator.rb
134
+ - lib/generators/railstank/templates/indextank.yml.example
135
+ - lib/generators/railstank/templates/load_indextank.rb
136
+ - lib/railstank.rb
137
+ - railstank.gemspec
138
+ - spec/railstank_spec.rb
139
+ - spec/spec_helper.rb
140
+ has_rdoc: true
141
+ homepage: http://github.com/xdite/railstank
142
+ licenses:
143
+ - MIT
144
+ post_install_message:
145
+ rdoc_options: []
146
+
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ hash: 3
155
+ segments:
156
+ - 0
157
+ version: "0"
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ hash: 3
164
+ segments:
165
+ - 0
166
+ version: "0"
167
+ requirements: []
168
+
169
+ rubyforge_project:
170
+ rubygems_version: 1.5.2
171
+ signing_key:
172
+ specification_version: 3
173
+ summary: indextank rails plugin
174
+ test_files:
175
+ - spec/railstank_spec.rb
176
+ - spec/spec_helper.rb