hashmodel 0.4.0.beta1 → 0.4.0.beta2
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/Gemfile.lock +1 -1
- data/LICENSE.txt +1 -1
- data/README.markdown +65 -27
- data/hashmodel.gemspec +1 -1
- data/lib/hash_model/hash_model.rb +13 -105
- data/lib/hash_model/hash_model_create_object.rb +62 -0
- data/lib/hash_model/hash_model_delete.rb +13 -0
- data/lib/hash_model/hash_model_filter.rb +37 -0
- data/lib/hash_model/hash_model_flatten.rb +47 -0
- data/lib/hash_model/hash_model_group.rb +18 -0
- data/lib/hash_model/hash_model_update.rb +118 -0
- data/lib/hash_model/hash_model_where.rb +27 -0
- data/lib/hash_model/version.rb +1 -1
- data/lib/hashmodel.rb +1 -0
- data/lib/monkey_patch/deep_clone.rb +27 -0
- data/spec/hash_model/_current_spec.rb +6 -0
- data/spec/hash_model/hash_model_adding_records_spec.rb +338 -0
- data/spec/hash_model/hash_model_array_methods_spec.rb +132 -0
- data/spec/hash_model/hash_model_comparisons_spec.rb +55 -0
- data/spec/hash_model/hash_model_delete_spec.rb +51 -0
- data/spec/hash_model/hash_model_flattening_spec.rb +92 -0
- data/spec/hash_model/hash_model_group_spec.rb +67 -0
- data/spec/hash_model/hash_model_searching_spec.rb +245 -0
- data/spec/hash_model/hash_model_spec.rb +1 -1
- data/spec/hash_model/hash_model_unflattening_spec.rb +34 -0
- data/spec/hash_model/hash_model_update_spec.rb +147 -0
- data/spec/hash_model/hash_model_where_spec.rb +287 -0
- data/spec/support/configuration.rb +50 -0
- data/spec/support/debug_print.rb +13 -0
- data/spec/support/proc_tester.rb +17 -0
- metadata +49 -27
- data/_brainstorm/StrangeMarshal.txt +0 -0
- data/_brainstorm/_readme +0 -1
- data/_brainstorm/block_wheres.rb +0 -80
- data/_brainstorm/clone.rb +0 -19
- data/_brainstorm/hash_model_examples.rb +0 -57
- data/_brainstorm/hash_test.rb +0 -169
- data/_brainstorm/inspect.rb +0 -26
- data/_brainstorm/instance_vars.rb +0 -24
- data/_brainstorm/proc_tests.rb +0 -14
- data/_brainstorm/ref_val.rb +0 -16
- data/_brainstorm/regex_captures.rb +0 -18
- data/_brainstorm/spliting.rb +0 -46
- data/_brainstorm/test.rb +0 -27
- data/_brainstorm/unflat.rb +0 -16
data/_brainstorm/inspect.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
class TestSelf
|
2
|
-
include Enumerable
|
3
|
-
|
4
|
-
attr_accessor :data
|
5
|
-
|
6
|
-
def initialize(data=[])
|
7
|
-
@data = data
|
8
|
-
end
|
9
|
-
|
10
|
-
def each
|
11
|
-
@data.each do |record|
|
12
|
-
yield record
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
@data.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
array = [1,2,3,4,5]
|
24
|
-
ts = TestSelf.new(array)
|
25
|
-
|
26
|
-
puts ts[2]
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class Foo
|
2
|
-
|
3
|
-
attr_accessor :bar
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@bar = 1
|
7
|
-
end
|
8
|
-
|
9
|
-
def show
|
10
|
-
vars = instance_variables
|
11
|
-
instance_variables.each do |var|
|
12
|
-
puts "var: #{var}"
|
13
|
-
end
|
14
|
-
print "no vars "
|
15
|
-
puts instance_variables.class
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
f = Foo.new
|
21
|
-
|
22
|
-
f.show
|
23
|
-
|
24
|
-
puts f.instance_variables
|
data/_brainstorm/proc_tests.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'sourcify'
|
2
|
-
@x = "x"
|
3
|
-
@y = "y"
|
4
|
-
|
5
|
-
search = proc{:x == "x" && :y == "y"}
|
6
|
-
|
7
|
-
@filter = search.to_source.match(/^proc { \((.*)\) }$/)[1]
|
8
|
-
puts "new_search: \"#{@filter}\""
|
9
|
-
puts "\nRun Eval"
|
10
|
-
puts instance_eval("proc { (#{@filter}) }.call".gsub(":", "@"))
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
data/_brainstorm/ref_val.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
string = "My phone number is (123) 555-1234."
|
2
|
-
phone_re = /\((\d{3})\)\s+(\d{3})-(\d{4})/
|
3
|
-
m = phone_re.match(string)
|
4
|
-
unless m
|
5
|
-
puts "There was no match..."
|
6
|
-
exit
|
7
|
-
end
|
8
|
-
print "The whole string we started with: "
|
9
|
-
puts m.string
|
10
|
-
print "The entire part of the string that matched: "
|
11
|
-
puts m[0]
|
12
|
-
puts "The three captures: "
|
13
|
-
m.captures.each do |cap|
|
14
|
-
puts "Capture ##{cap}"
|
15
|
-
end
|
16
|
-
puts "Here's another way to get at the first capture:"
|
17
|
-
print "Capture #1: "
|
18
|
-
puts m[1]
|
data/_brainstorm/spliting.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
|
2
|
-
def deflatten(input)
|
3
|
-
case input
|
4
|
-
when Hash
|
5
|
-
new_hash = {}
|
6
|
-
input.each do |key,value|
|
7
|
-
split_key = key.to_s.split("__",2)
|
8
|
-
new_hash_key = split_key[0].to_sym
|
9
|
-
if split_key.length > 1
|
10
|
-
child_hash = {split_key[1].to_sym => value}
|
11
|
-
value = deflatten(child_hash)
|
12
|
-
end
|
13
|
-
|
14
|
-
#look for existing keys so we don't overwrite them
|
15
|
-
existing_value = new_hash[new_hash_key]
|
16
|
-
if !existing_value.nil?
|
17
|
-
if existing_value.class == Hash && value.class == Hash
|
18
|
-
value = existing_value.merge(value)
|
19
|
-
elsif existing_value.class == Array
|
20
|
-
value = existing_value << value
|
21
|
-
else
|
22
|
-
value = [value, existing_value]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
new_hash.merge!(new_hash_key => value)
|
26
|
-
end
|
27
|
-
new_hash
|
28
|
-
when Array
|
29
|
-
input.collect { |value| deflatten(value.clone)}
|
30
|
-
else
|
31
|
-
input
|
32
|
-
end # case
|
33
|
-
end
|
34
|
-
|
35
|
-
hash = {:switch=>"-x", :parameter__type=>String, :parameter__required=>true, :some__value__blrop=>[1,2,3], :some__hash=>{:blah=>"bloo", :bleep=>4}, :some__value=>"something", :some__others=>"others", :some__array=> [1,2,3], :description=>"the x paramemter"}
|
36
|
-
|
37
|
-
puts ""
|
38
|
-
puts ""
|
39
|
-
puts "build_hash: #{deflatten(hash)}"
|
40
|
-
|
41
|
-
{
|
42
|
-
:switch=>"-x",
|
43
|
-
:parameter=>{:required=>true, :type=>String},
|
44
|
-
:some=>{:array=>[1, 2, 3], :others=>"others", :value=>[{:blrop=>[1,2,3]}, "something"], :hash=>{:blah=>"bloo", :bleep=>4}},
|
45
|
-
:description=>"the x paramemter"
|
46
|
-
}
|
data/_brainstorm/test.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
class Fruit
|
2
|
-
|
3
|
-
def set_defaults
|
4
|
-
@color ||= 'green'
|
5
|
-
@type ||= 'pear'
|
6
|
-
end
|
7
|
-
|
8
|
-
def initialize(params = {})
|
9
|
-
params.each { |key,value| instance_variable_set("@#{key}", value) }
|
10
|
-
set_defaults
|
11
|
-
instance_variables.each {|var| self.class.send(:attr_accessor, var)}
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
instance_variables.inject("") {|vars, var| vars += "#{var}: #{instance_variable_get(var)}; "}
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
puts Fruit.new
|
21
|
-
puts Fruit.new :color => 'red', :type => 'grape'
|
22
|
-
puts Fruit.new :type => 'pomegranate'
|
23
|
-
puts Fruit.new :cost => 20.21
|
24
|
-
puts Fruit.new :foo => "bar"
|
25
|
-
|
26
|
-
f = Fruit.new :potato => "salad"
|
27
|
-
puts "f.cost.nil? #{f.cost.nil?}"
|
data/_brainstorm/unflat.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "/../lib"))
|
2
|
-
require 'hash_model'
|
3
|
-
|
4
|
-
deep_hash = {
|
5
|
-
:parameter__type=>String,
|
6
|
-
:switch__deep1__deep3 => "deepTwo",
|
7
|
-
:parameter__type__ruby=>true,
|
8
|
-
:parameter => "glorp",
|
9
|
-
:parameter__require=>true,
|
10
|
-
:switch__deep2 => "deepTwo",
|
11
|
-
:description=>"Xish stuff",
|
12
|
-
:switch => "--xtend",
|
13
|
-
}
|
14
|
-
unflat = HashModel.unflatten(deep_hash)
|
15
|
-
|
16
|
-
puts unflat
|