acts_as_shellscript_executable 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 722aca7c7a8f0e82959146778aca5747f639e3f5
4
+ data.tar.gz: 7d7676df80465c0edb8f14a4c09a301612aebafb
5
+ SHA512:
6
+ metadata.gz: 4d809017d6ff92571c6541f34124520e43013586f31ccfbb30b5fbe33e1486a1860fc054f6f7410dfe548637436da1e44dd7384e4d3e4a5ec63ba7a329649a8c
7
+ data.tar.gz: bd773b89ce5a3dd93e347d089f83a80c00b4b51d5e28b70f9a01b59bb88413263923840f4770f8bd1676180f7bc1e18b308710631e9c3d25fcae0749ba4b9360
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - 2.1.0
5
+ - 2.0.0
6
+ - 1.9.3
7
+ - 'ruby-head'
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in acts_as_shellscript_executable.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', require: false
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 hoshinotsuyoshi
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.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # ActsAsShellscriptExecutable
2
+
3
+ [![travis-batch](https://travis-ci.org/hoshinotsuyoshi/acts_as_shellscript_executable.svg)](https://travis-ci.org/hoshinotsuyoshi/acts_as_shellscript_executable)
4
+ [![Coverage Status](https://coveralls.io/repos/hoshinotsuyoshi/acts_as_shellscript_executable/badge.png)](https://coveralls.io/r/hoshinotsuyoshi/acts_as_shellscript_executable)
5
+ [![Code Climate](https://codeclimate.com/github/hoshinotsuyoshi/acts_as_shellscript_executable/badges/gpa.svg)](https://codeclimate.com/github/hoshinotsuyoshi/acts_as_shellscript_executable)
6
+
7
+
8
+ class Script < ActiveRecord::Base
9
+ acts_as_shellscript_executable script: :script, stdout: :result
10
+ end
11
+
12
+ ### before:
13
+
14
+ | id | name | script | result |
15
+ | :------|:------ |:---------------|:-----|
16
+ | 1 | foo | echo 'lalala' | |
17
+
18
+
19
+ ### execute:
20
+
21
+ script = Script.find(1)
22
+ script.execute!
23
+
24
+ ### after:
25
+
26
+ | id | name | script | result |
27
+ | :------|:------ |:---------------|:-----|
28
+ | 1 | foo | echo 'lalala' | lalala |
29
+
30
+ ## Installation
31
+
32
+ Add this line to your application's Gemfile:
33
+
34
+ gem 'acts_as_shellscript_executable'
35
+
36
+ And then execute:
37
+
38
+ $ bundle
39
+
40
+ Or install it yourself as:
41
+
42
+ $ gem install acts_as_shellscript_executable
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( http://github.com/<my-github-username>/acts_as_shellscript_executable/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'acts_as_shellscript_executable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "acts_as_shellscript_executable"
8
+ spec.version = ActiveRecord::Acts::ShellscriptExecutable::VERSION
9
+ spec.authors = ["hoshinotsuyoshi"]
10
+ spec.email = ["guitarpopnot330@gmail.com"]
11
+ spec.summary = %q{#execute! executes column's content as shellscript}
12
+ spec.description = %q{}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_development_dependency "sqlite3"
26
+
27
+ spec.required_ruby_version = '>= 1.9.3'
28
+
29
+ spec.add_dependency("activerecord", [">= 4.1.6"])
30
+ end
@@ -0,0 +1,52 @@
1
+ module ActiveRecord
2
+ module Acts
3
+ module ShellscriptExecutable
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ def acts_as_shellscript_executable(options = {})
10
+ @@configuration = { script: :script, stdout: nil }
11
+ @@configuration.update(options) if options.is_a?(Hash)
12
+
13
+ class_eval <<-EOV
14
+ include ::ActiveRecord::Acts::ShellscriptExecutable::InstanceMethods
15
+
16
+ EOV
17
+ end
18
+
19
+ def configuration
20
+ @@configuration
21
+ end
22
+ end
23
+
24
+ module InstanceMethods
25
+ def execute!
26
+ script = configuration[:script]
27
+ stdout = configuration[:stdout]
28
+ if configuration[:fork]
29
+ fork { execute(script, stdout) }
30
+ # for test
31
+ Process.wait if ENV['test']
32
+ else
33
+ execute(script, stdout)
34
+ end
35
+ end
36
+
37
+ private
38
+ def configuration
39
+ self.class.configuration
40
+ end
41
+
42
+ def execute(script, stdout)
43
+ retval = %x(#{send script})
44
+ if stdout && respond_to?("#{stdout}=".to_sym)
45
+ send("#{stdout}=".to_sym, retval)
46
+ end
47
+ save!
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,7 @@
1
+ module ActiveRecord
2
+ module Acts
3
+ module ShellscriptExecutable
4
+ VERSION = '0.0.0'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require 'acts_as_shellscript_executable/version'
2
+ require 'acts_as_shellscript_executable/active_record/acts/shellscript_executable'
3
+
4
+ module ActsAsShellscriptExecutable
5
+ if defined? Rails::Railtie
6
+ require 'rails'
7
+ class Railtie < Rails::Railtie
8
+ initializer 'acts_as_shellscript_executable.insert_into_active_record' do
9
+ ActiveSupport.on_load :active_record do
10
+ ActsAsShellscriptExecutable::Railtie.insert
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ class Railtie
17
+ def self.insert
18
+ if defined?(ActiveRecord)
19
+ require 'active_record'
20
+ ActiveRecord::Base.send(:include, ActiveRecord::Acts::ShellscriptExecutable)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ ActsAsShellscriptExecutable::Railtie.insert
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+ require 'tmpdir'
3
+
4
+ describe ActiveRecord::Base do
5
+ describe '.acts_as_shellscript_executable' do
6
+ def db_setup!
7
+ # use not-in-memory-sqlite-db. because of fork
8
+ db_dir = Dir.mktmpdir('db')
9
+ ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: "#{db_dir}/db.sqlite3")
10
+ ActiveRecord::Schema.verbose = false
11
+ ActiveRecord::Base.connection.schema_cache.clear!
12
+ ActiveRecord::Schema.define(version: 1) do
13
+ create_table :scripts do |t|
14
+ t.column :script, :string
15
+ t.column :script2, :string
16
+ t.column :result, :string
17
+ end
18
+ end
19
+ end
20
+
21
+ before do
22
+ db_setup!
23
+ end
24
+
25
+ context 'given option {script: :script}' do
26
+ before do
27
+ class Script < ActiveRecord::Base
28
+ acts_as_shellscript_executable script: :script
29
+ end
30
+ end
31
+
32
+ it do
33
+ script = Script.create
34
+ script.script = 'echo "lalala"'
35
+ expect{script.execute!}.to_not \
36
+ change{script.result}
37
+ end
38
+ end
39
+
40
+ context 'given option {script: :script, stdout: :result}' do
41
+ before do
42
+ class Script < ActiveRecord::Base
43
+ acts_as_shellscript_executable script: :script, stdout: :result
44
+ end
45
+ end
46
+
47
+ it do
48
+ script = Script.create
49
+ script.script = 'echo "lalala"'
50
+ expect{script.execute!}.to \
51
+ change{script.result}.from(nil).to("lalala\n")
52
+ end
53
+ end
54
+
55
+ describe 'given option fork' do
56
+ context 'given option {script: :script, stdout: :result, fork: false}' do
57
+ before do
58
+ class Script < ActiveRecord::Base
59
+ acts_as_shellscript_executable script: :script, stdout: :result, fork: false
60
+ end
61
+ end
62
+
63
+ it do
64
+ script = Script.create
65
+ pid = Process.pid
66
+ script.script = 'echo $PPID' # this $PPID is equal to $$
67
+ expect{script.execute!}.to \
68
+ change{script.result}.from(nil).to("#{Process.pid}\n")
69
+ end
70
+ end
71
+
72
+ context '[forking] given option {script: :script, stdout: :result, fork: true}' do
73
+ before do
74
+ class Script < ActiveRecord::Base
75
+ acts_as_shellscript_executable script: :script, stdout: :result, fork: true
76
+ end
77
+
78
+ @script = Script.create
79
+ @script.script = 'echo $PPID' # when fork, this $PPID is not equal to $$
80
+ @script.execute!
81
+ end
82
+
83
+ it do
84
+ # reset object because of fork
85
+ @script = Script.find @script.id
86
+ expect(@script.result).not_to equal nil
87
+ expect(@script.result).not_to eq("#{Process.pid}\n")
88
+ end
89
+ end
90
+ end
91
+
92
+ context 'given option {script: :script2, stdout: :result}' do
93
+ before do
94
+ class Script < ActiveRecord::Base
95
+ acts_as_shellscript_executable script: :script2, stdout: :result
96
+ end
97
+ end
98
+
99
+ it do
100
+ script = Script.create
101
+ script.script = 'echo "hehehe"'
102
+ script.script2 = 'echo "lalala"'
103
+ expect{script.execute!}.to \
104
+ change{script.result}.from(nil).to("lalala\n")
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,7 @@
1
+ require 'coveralls'
2
+ Coveralls.wear!
3
+ ENV['test'] = 'true'
4
+
5
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
6
+ require 'acts_as_shellscript_executable'
7
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_shellscript_executable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - hoshinotsuyoshi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 4.1.6
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 4.1.6
97
+ description: ''
98
+ email:
99
+ - guitarpopnot330@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".ruby-version"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - acts_as_shellscript_executable.gemspec
113
+ - lib/acts_as_shellscript_executable.rb
114
+ - lib/acts_as_shellscript_executable/active_record/acts/shellscript_executable.rb
115
+ - lib/acts_as_shellscript_executable/version.rb
116
+ - spec/features/acts_as_shellscript_executable_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: ''
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 1.9.3
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: "#execute! executes column's content as shellscript"
142
+ test_files:
143
+ - spec/features/acts_as_shellscript_executable_spec.rb
144
+ - spec/spec_helper.rb