subtle 1.0.0 → 1.1.0
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.
- data/.rvmrc +25 -32
- data/.travis.yml +0 -3
- data/README.md +24 -0
- data/lib/subtle/array_to_hashes.rb +23 -0
- data/lib/subtle/version.rb +1 -1
- data/spec/subtle/array_to_hashes_spec.rb +100 -0
- metadata +68 -71
data/.rvmrc
CHANGED
@@ -3,53 +3,46 @@
|
|
3
3
|
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
4
|
# development environment upon cd'ing into the directory
|
5
5
|
|
6
|
-
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional
|
7
|
-
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-head"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.17.0 (master)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
8
17
|
|
9
|
-
#
|
10
|
-
# Uncomment following line if you want options to be set only for given project.
|
11
|
-
#
|
12
|
-
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
-
|
14
|
-
#
|
15
18
|
# First we attempt to load the desired environment directly from the environment
|
16
19
|
# file. This is very fast and efficient compared to running through the entire
|
17
20
|
# CLI and selector. If you want feedback on which environment was used then
|
18
21
|
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
-
|
20
|
-
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
21
23
|
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
24
|
then
|
23
25
|
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
-
|
25
|
-
|
26
|
-
then
|
27
|
-
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
-
fi
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
29
28
|
else
|
30
29
|
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
-
|
32
|
-
then
|
30
|
+
rvm --create "$environment_id" || {
|
33
31
|
echo "Failed to create RVM environment '${environment_id}'."
|
34
32
|
return 1
|
35
|
-
|
33
|
+
}
|
36
34
|
fi
|
37
35
|
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# filename=".gems"
|
44
|
-
# if [[ -s "$filename" ]]
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
45
41
|
# then
|
46
|
-
#
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
47
44
|
# fi
|
48
|
-
|
49
|
-
# If you use bundler, this might be useful to you:
|
50
|
-
# if command -v bundle && [[ -s Gemfile ]]
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
51
46
|
# then
|
52
|
-
# bundle install
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
53
48
|
# fi
|
54
|
-
|
55
|
-
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# Subtle [](http://travis-ci.org/darrencauthon/subtle)
|
2
|
+
[](https://codeclimate.com/github/darrencauthon/subtle)
|
3
|
+
|
2
4
|
|
3
5
|
This library contains methods that seem to cut down a litle bit of the code that I write daily.
|
4
6
|
|
@@ -29,6 +31,28 @@ records[2].first_name # "Dagny"
|
|
29
31
|
records[2].last_name # "Taggart"
|
30
32
|
````
|
31
33
|
|
34
|
+
### Arrays to Hashes
|
35
|
+
|
36
|
+
This feature exists to create a set of hashes with the same properties, but to only defined the keys once.
|
37
|
+
|
38
|
+
````ruby
|
39
|
+
records = [:first_name, :last_name].to_hashes {
|
40
|
+
[
|
41
|
+
["John", "Galt" ],
|
42
|
+
["Howard", "Roark" ],
|
43
|
+
["Dagny", "Taggart"]
|
44
|
+
]}
|
45
|
+
|
46
|
+
records[0][:first_name] # "John"
|
47
|
+
records[0][:last_name] # "Galt"
|
48
|
+
|
49
|
+
records[1][:first_name] # "Howard"
|
50
|
+
records[1][:last_name] # "Roark"
|
51
|
+
|
52
|
+
records[2][:first_name] # "Dagny"
|
53
|
+
records[2][:last_name] # "Taggart"
|
54
|
+
````
|
55
|
+
|
32
56
|
### Array to Object
|
33
57
|
|
34
58
|
This feature exists to make the creation of an object with assignable properties easy.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Array
|
2
|
+
|
3
|
+
def to_hashes(test = nil, &block_that_returns_the_records)
|
4
|
+
records = block_that_returns_the_records.call
|
5
|
+
return [] if records.empty?
|
6
|
+
records.map { |record| turn_this_data_into_a_filled_hash(record) }
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def turn_this_data_into_a_filled_hash(record)
|
12
|
+
result = {}
|
13
|
+
fill_the_hash_with_the_values(result, record)
|
14
|
+
result
|
15
|
+
end
|
16
|
+
|
17
|
+
def fill_the_hash_with_the_values(result, record)
|
18
|
+
self.each_with_index do |field, index|
|
19
|
+
value = get_the_value(record, index)
|
20
|
+
result[field] = value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/subtle/version.rb
CHANGED
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "arrays to hashes" do
|
4
|
+
|
5
|
+
describe "creating hashes with matching attr_accessors and values" do
|
6
|
+
[:name, :street].each do |property|
|
7
|
+
describe "with an array with one symbol named #{property.to_s}" do
|
8
|
+
describe "and no data" do
|
9
|
+
before do
|
10
|
+
@values = [property].to_hashes { [] }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return an empty array" do
|
14
|
+
@values.must_be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
["Dangy", "Taggart"].each do |name|
|
19
|
+
describe "and one record with #{name}" do
|
20
|
+
before do
|
21
|
+
@values = [property].to_hashes { [name] }
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return one record" do
|
25
|
+
@values.count.must_equal 1
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should have a property with the name of Dangy" do
|
29
|
+
@values[0][property].must_equal name
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "and two records with John and Howard" do
|
35
|
+
before do
|
36
|
+
@values = [property].to_hashes {["John", "Howard"]}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return two records" do
|
40
|
+
@values.count.must_equal 2
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should set the first to John" do
|
44
|
+
@values[0][property].must_equal "John"
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should set the second to Howard" do
|
48
|
+
@values[1][property].must_equal "Howard"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "with an array with two symbols named first_name and last_name" do
|
54
|
+
describe "with 'Ellis' and 'Wyatt'" do
|
55
|
+
before do
|
56
|
+
@values = [:first_name, :last_name].to_hashes { [['Ellis', 'Wyatt']] }
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should return one record" do
|
60
|
+
@values.count.must_equal 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should set the first name to Ellis" do
|
64
|
+
@values[0][:first_name].must_equal 'Ellis'
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should set the last name to Wyatt" do
|
68
|
+
@values[0][:last_name].must_equal 'Wyatt'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "with 'Ellis' and 'Wyatt', then 'Dagny' and 'Taggart'" do
|
73
|
+
before do
|
74
|
+
@values = [:first_name, :last_name].to_hashes { [['Ellis', 'Wyatt'], ['Dagny', 'Taggart']] }
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return one record" do
|
78
|
+
@values.count.must_equal 2
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set the first name to Ellis on the first record" do
|
82
|
+
@values[0][:first_name].must_equal 'Ellis'
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should set the last name to Wyatt on the first record" do
|
86
|
+
@values[0][:last_name].must_equal 'Wyatt'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should set the first name to Dagny on the second record" do
|
90
|
+
@values[1][:first_name].must_equal 'Dagny'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should set the last name to Wyatt on the second record" do
|
94
|
+
@values[1][:last_name].must_equal 'Taggart'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
CHANGED
@@ -1,74 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: subtle
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 0
|
10
|
-
version: 1.0.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Darren Cauthon
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
-
none: false
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 3
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
version: "0"
|
30
|
-
prerelease: false
|
31
|
-
type: :runtime
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
32
15
|
name: blankslate
|
33
|
-
requirement:
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
36
17
|
none: false
|
37
|
-
requirements:
|
38
|
-
- -
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
|
41
|
-
|
42
|
-
- 0
|
43
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
44
23
|
prerelease: false
|
45
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
46
31
|
name: mocha
|
47
|
-
requirement:
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
50
33
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
segments:
|
56
|
-
- 0
|
57
|
-
version: "0"
|
58
|
-
prerelease: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
59
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
|
60
47
|
name: rake
|
61
|
-
requirement:
|
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
62
|
description: A few small updates to make even more concise Ruby.
|
63
|
-
email:
|
63
|
+
email:
|
64
64
|
- darren@cauthon.com
|
65
65
|
executables: []
|
66
|
-
|
67
66
|
extensions: []
|
68
|
-
|
69
67
|
extra_rdoc_files: []
|
70
|
-
|
71
|
-
files:
|
68
|
+
files:
|
72
69
|
- .gitignore
|
73
70
|
- .rvmrc
|
74
71
|
- .travis.yml
|
@@ -78,6 +75,7 @@ files:
|
|
78
75
|
- README.md
|
79
76
|
- Rakefile
|
80
77
|
- lib/subtle.rb
|
78
|
+
- lib/subtle/array_to_hashes.rb
|
81
79
|
- lib/subtle/array_to_objects.rb
|
82
80
|
- lib/subtle/cover.rb
|
83
81
|
- lib/subtle/lambda_to_object.rb
|
@@ -86,6 +84,7 @@ files:
|
|
86
84
|
- lib/subtle/safety_proc.rb
|
87
85
|
- lib/subtle/version.rb
|
88
86
|
- spec/spec_helper.rb
|
87
|
+
- spec/subtle/array_to_hashes_spec.rb
|
89
88
|
- spec/subtle/array_to_object_spec.rb
|
90
89
|
- spec/subtle/array_to_objects_spec.rb
|
91
90
|
- spec/subtle/cover_spec.rb
|
@@ -96,39 +95,37 @@ files:
|
|
96
95
|
- subtle.gemspec
|
97
96
|
homepage: http://www.github.com/darrencauthon/subtle
|
98
97
|
licenses: []
|
99
|
-
|
100
98
|
post_install_message:
|
101
99
|
rdoc_options: []
|
102
|
-
|
103
|
-
require_paths:
|
100
|
+
require_paths:
|
104
101
|
- lib
|
105
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
103
|
none: false
|
107
|
-
requirements:
|
108
|
-
- -
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
|
111
|
-
segments:
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
112
109
|
- 0
|
113
|
-
|
114
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
hash: 787413255858231210
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
112
|
none: false
|
116
|
-
requirements:
|
117
|
-
- -
|
118
|
-
- !ruby/object:Gem::Version
|
119
|
-
|
120
|
-
segments:
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
segments:
|
121
118
|
- 0
|
122
|
-
|
119
|
+
hash: 787413255858231210
|
123
120
|
requirements: []
|
124
|
-
|
125
121
|
rubyforge_project:
|
126
122
|
rubygems_version: 1.8.24
|
127
123
|
signing_key:
|
128
124
|
specification_version: 3
|
129
125
|
summary: A few small updates to make even more concise Ruby.
|
130
|
-
test_files:
|
126
|
+
test_files:
|
131
127
|
- spec/spec_helper.rb
|
128
|
+
- spec/subtle/array_to_hashes_spec.rb
|
132
129
|
- spec/subtle/array_to_object_spec.rb
|
133
130
|
- spec/subtle/array_to_objects_spec.rb
|
134
131
|
- spec/subtle/cover_spec.rb
|