ruboty-sql 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7289750f42796d4afaedfc9290c7a59bf37b7a9f
4
+ data.tar.gz: 12984f15c0c3159a4b041f6fd595f5f20ddb571e
5
+ SHA512:
6
+ metadata.gz: 81750ff4211482e7d3fe39389e72ea711bc73461f3761c07508d67baf0dd8c14dc714d9eea49fcd1d8e5514ab3155c7f8db4ea4402f602bf35a322e4e961e701
7
+ data.tar.gz: af1533ea50bc7b86f9ef8912b323d699d588ac43c3724341ebf63fb7fe526d42cb58cf7d210d888195ee5af9247615afe0d30d8d16c6eb1e175b7347d0836ed8
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .env
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruboty-sql.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yoshiori SHOJI
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.
@@ -0,0 +1,60 @@
1
+ # Ruboty::Sql
2
+
3
+ Sql handler for Ruboty.
4
+
5
+ ![](slack.png)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-sql'
13
+ gem 'sqlite3' # Your database library
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ > ruboty sql select * from incenses;
24
+ +----------------------------+----+--------+----------------------------+---------+
25
+ | created_at | id | source | updated_at | user_id |
26
+ +----------------------------+----+--------+----------------------------+---------+
27
+ | 2015-03-02 20:48:36.990325 | 1 | | 2015-03-02 20:48:36.990325 | 1 |
28
+ | 2015-03-03 18:49:27.894872 | 2 | | 2015-03-03 18:49:27.894872 | 2 |
29
+ | 2015-03-07 16:19:12.756657 | 3 | | 2015-03-07 16:19:12.756657 | 1 |
30
+ | 2015-03-10 11:11:38.409086 | 4 | api | 2015-03-10 11:11:38.409086 | 1 |
31
+ +----------------------------+----+--------+----------------------------+---------+
32
+ 4 rows in set
33
+ ```
34
+
35
+ ## ENV
36
+ like rails's database.yml.
37
+
38
+
39
+ add prefix `RUBOTY_SQL_`
40
+
41
+ adapter => RUBOTY_SQL_ADAPTER
42
+
43
+ username => RUBOTY_SQL_USERNAME
44
+
45
+ ### security (strongly recommended)
46
+ Create **readonly** user.
47
+
48
+ ### example for sqlite3
49
+
50
+ ```
51
+ RUBOTY_SQL_ADAPTER=sqlite3
52
+ RUBOTY_SQL_DATABASE=/path/to/sqlite3.db
53
+ ```
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/yoshiori/ruboty-sql/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,28 @@
1
+ require "active_record"
2
+ require "hirb"
3
+
4
+ module Ruboty
5
+ module Handlers
6
+ class Sql < Base
7
+ on(/sql (?<sql>.*)/, name: "run_sql", description: "run sql")
8
+
9
+ config = Hash[ENV.keys.select { |key|
10
+ key.start_with? "RUBOTY_SQL_"
11
+ }.map{ |key|
12
+ [key.gsub("RUBOTY_SQL_", "").downcase, ENV[key]]
13
+ }]
14
+ ActiveRecord::Base.establish_connection(config)
15
+
16
+ private
17
+
18
+ def run_sql(message)
19
+ sql = message[:sql]
20
+ result = ActiveRecord::Base.connection.select_all(sql)
21
+
22
+ message.reply(Hirb::Helpers::AutoTable.render(result[0...20]), code: true)
23
+ rescue => e
24
+ message.reply(e)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,2 @@
1
+ require "ruboty/sql/version"
2
+ require "ruboty/handlers/sql"
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Sql
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/sql/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-sql"
7
+ spec.version = Ruboty::Sql::VERSION
8
+ spec.authors = ["Yoshiori SHOJI"]
9
+ spec.email = ["yoshiori@gmail.com"]
10
+ spec.summary = "Sql handler for Ruboty"
11
+ spec.homepage = "https://github.com/yoshiori/ruboty-sql"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency "ruboty"
20
+ spec.add_dependency "activerecord"
21
+ spec.add_dependency "hirb"
22
+ spec.add_dependency "hirb-unicode"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "pry"
27
+ end
Binary file
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-sql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yoshiori SHOJI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: activerecord
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: hirb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hirb-unicode
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
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
+ description:
112
+ email:
113
+ - yoshiori@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/ruboty/handlers/sql.rb
124
+ - lib/ruboty/sql.rb
125
+ - lib/ruboty/sql/version.rb
126
+ - ruboty-sql.gemspec
127
+ - slack.png
128
+ homepage: https://github.com/yoshiori/ruboty-sql
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Sql handler for Ruboty
152
+ test_files: []