trickery 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +1 -0
- data/lib/trickery.rb +8 -0
- data/lib/trickery/cmd_runner.rb +51 -0
- data/lib/trickery/config.rb +15 -0
- data/lib/trickery/deep_ostruct.rb +22 -0
- data/lib/trickery/version.rb +3 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/trickery/deep_ostruct_spec.rb +15 -0
- data/trickery.gemspec +27 -0
- metadata +147 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014,2015 phil
|
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,36 @@
|
|
1
|
+
_____ _ _
|
2
|
+
|_ _| __(_) ___| | _____ _ __ _ _
|
3
|
+
| || '__| |/ __| |/ / _ \ '__| | | |
|
4
|
+
| || | | | (__| < __/ | | |_| |
|
5
|
+
|_||_| |_|\___|_|\_\___|_| \__, |
|
6
|
+
|___/
|
7
|
+
|
8
|
+
# Welcome to Trickery
|
9
|
+
|
10
|
+
Reusable ruby trickery.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'trickery'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install trickery
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
TODO: Write usage instructions here
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/trickery.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'systemu'
|
2
|
+
|
3
|
+
# Example Usage
|
4
|
+
#
|
5
|
+
# class A
|
6
|
+
# include Trickery::CmdRunner
|
7
|
+
#
|
8
|
+
# def hello
|
9
|
+
# hello
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# private
|
13
|
+
#
|
14
|
+
# def hello_cmd
|
15
|
+
# 'echo hello'
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
module Trickery
|
20
|
+
module CmdRunner
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def run_cmd(method, *args)
|
25
|
+
cmds = send(method, *args)
|
26
|
+
|
27
|
+
stdout = '(no output)'
|
28
|
+
|
29
|
+
cmds.split("\n").each do |cmd|
|
30
|
+
# log if a logger is present
|
31
|
+
logger.debug("% #{cmd}") if respond_to?(:logger)
|
32
|
+
|
33
|
+
status, stdout, stderr = systemu(cmd)
|
34
|
+
|
35
|
+
if respond_to?(:logger)
|
36
|
+
logger.debug(stdout)
|
37
|
+
logger.warn(stderr)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
stdout
|
42
|
+
end
|
43
|
+
|
44
|
+
def method_missing(method, *args)
|
45
|
+
cmd_method = "#{method}_cmd"
|
46
|
+
return run_cmd(cmd_method, *args) if respond_to?(cmd_method)
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Trickery
|
4
|
+
module DeepOstruct
|
5
|
+
|
6
|
+
def deep_ostruct(opts)
|
7
|
+
OpenStruct.new.tap do |o|
|
8
|
+
opts.each do |key, value|
|
9
|
+
o.send key.to_s + '=',
|
10
|
+
case value
|
11
|
+
when Hash
|
12
|
+
deep_ostruct(value)
|
13
|
+
when Array
|
14
|
+
value.map { |v| deep_ostruct(v) }
|
15
|
+
else value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Trickery::DeepOstruct do
|
4
|
+
|
5
|
+
let(:object) { Class.new { include(Trickery::DeepOstruct) }.new }
|
6
|
+
|
7
|
+
it 'returns an OpenStruct' do
|
8
|
+
assert { object.deep_ostruct(a: 1).is_a?(OpenStruct) }
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'works deeply' do
|
12
|
+
assert { object.deep_ostruct(a: {b: 42}).a.b == 42 }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/trickery.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'trickery/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "trickery"
|
8
|
+
spec.version = Trickery::VERSION
|
9
|
+
spec.authors = ["phil"]
|
10
|
+
spec.email = ["phil@branch14.org"]
|
11
|
+
spec.description = %q{Reusable ruby trickery.}
|
12
|
+
spec.summary = %q{Reusable ruby trickery.}
|
13
|
+
spec.homepage = "https://github.com/branch14/trickery"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "wrong"
|
25
|
+
|
26
|
+
spec.add_dependency "systemu"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trickery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- phil
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: wrong
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: systemu
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Reusable ruby trickery.
|
95
|
+
email:
|
96
|
+
- phil@branch14.org
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- lib/trickery.rb
|
107
|
+
- lib/trickery/cmd_runner.rb
|
108
|
+
- lib/trickery/config.rb
|
109
|
+
- lib/trickery/deep_ostruct.rb
|
110
|
+
- lib/trickery/version.rb
|
111
|
+
- spec/spec_helper.rb
|
112
|
+
- spec/trickery/deep_ostruct_spec.rb
|
113
|
+
- trickery.gemspec
|
114
|
+
homepage: https://github.com/branch14/trickery
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
segments:
|
128
|
+
- 0
|
129
|
+
hash: -4414155239521418392
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
hash: -4414155239521418392
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 1.8.23
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: Reusable ruby trickery.
|
145
|
+
test_files:
|
146
|
+
- spec/spec_helper.rb
|
147
|
+
- spec/trickery/deep_ostruct_spec.rb
|