hammock 0.5.8 → 0.5.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/hammock.gemspec +3 -3
- data/lib/hammock/logging.rb +2 -1
- data/lib/hammock/monkey_patches/active_record.rb +1 -1
- data/lib/hammock/monkey_patches/hash.rb +15 -3
- data/lib/hammock/restful_support.rb +12 -5
- metadata +29 -13
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.9
|
data/hammock.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hammock}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ben Hoskings"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-05-12}
|
13
13
|
s.description = %q{}
|
14
14
|
s.email = %q{ben@hoskings.net}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -75,7 +75,7 @@ Gem::Specification.new do |s|
|
|
75
75
|
s.homepage = %q{http://github.com/benhoskings/hammock}
|
76
76
|
s.rdoc_options = ["--charset=UTF-8"]
|
77
77
|
s.require_paths = ["lib"]
|
78
|
-
s.rubygems_version = %q{1.3.
|
78
|
+
s.rubygems_version = %q{1.3.6}
|
79
79
|
s.summary = %q{Radically RESTful Rails.}
|
80
80
|
|
81
81
|
if s.respond_to? :specification_version then
|
data/lib/hammock/logging.rb
CHANGED
@@ -64,6 +64,7 @@ module Hammock
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def log_fail *args
|
67
|
+
opts = args.extract_options!
|
67
68
|
log *(args << opts.merge(:skip => (opts[:skip] || 0) + 1))
|
68
69
|
false
|
69
70
|
end
|
@@ -84,7 +85,7 @@ module Hammock
|
|
84
85
|
args.map(&:inspect).join(', ')
|
85
86
|
end
|
86
87
|
|
87
|
-
msg.colorize
|
88
|
+
msg = msg.colorize('on red') if opts[:error] || opts[:report]
|
88
89
|
|
89
90
|
callpoint = caller[opts[:skip]].sub(rails_root.end_with('/'), '')
|
90
91
|
entry = "#{callpoint}#{msg.blank? ? (opts[:report] ? ' <-- something broke here' : '.') : ' | '}#{msg}"
|
@@ -22,11 +22,10 @@ module Hammock
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def selekt &block
|
25
|
-
|
26
|
-
each_pair {|k,v|
|
25
|
+
inject({}) {|hsh,(k,v)|
|
27
26
|
hsh[k] = v if yield(k,v)
|
27
|
+
hsh
|
28
28
|
}
|
29
|
-
hsh
|
30
29
|
end
|
31
30
|
|
32
31
|
# TODO remove in favour of #slice (in ActiveSupport).
|
@@ -53,6 +52,19 @@ module Hammock
|
|
53
52
|
to_param_hash.to_json
|
54
53
|
end
|
55
54
|
|
55
|
+
def reject_r &block
|
56
|
+
dup.reject_r! &block
|
57
|
+
end
|
58
|
+
|
59
|
+
def reject_r! &block
|
60
|
+
each_pair {|k,v|
|
61
|
+
if yield k, v
|
62
|
+
self.delete k
|
63
|
+
elsif v.is_a? Hash
|
64
|
+
self[k] = v.reject_r &block
|
65
|
+
end
|
66
|
+
}
|
67
|
+
end
|
56
68
|
end
|
57
69
|
end
|
58
70
|
end
|
@@ -19,14 +19,18 @@ module Hammock
|
|
19
19
|
|
20
20
|
# The model this controller operates on. Defined as the singularized controller name. For example, for +GelatinousBlobsController+, this will return the +GelatinousBlob+ class.
|
21
21
|
def mdl
|
22
|
-
@hammock_cached_mdl ||= Object.const_get to_s.sub('Controller', '').classify
|
22
|
+
@hammock_cached_mdl ||= Object.const_get controller_ref.to_s.sub('Controller', '').classify
|
23
23
|
rescue
|
24
24
|
log "Error loading '#{to_s.sub('Controller', '').classify}': #{$!}."
|
25
25
|
nil
|
26
26
|
end
|
27
27
|
# The lowercase name of the model this controller operates on. For example, for +GelatinousBlobsController+, this will return "gelatinous_blob".
|
28
28
|
def mdl_name
|
29
|
-
@hammock_cached_mdl_name ||= to_s.sub('Controller', '').singularize.underscore
|
29
|
+
@hammock_cached_mdl_name ||= controller_ref.to_s.sub('Controller', '').singularize.underscore
|
30
|
+
end
|
31
|
+
|
32
|
+
def controller_ref
|
33
|
+
self
|
30
34
|
end
|
31
35
|
|
32
36
|
end
|
@@ -43,6 +47,10 @@ module Hammock
|
|
43
47
|
self.class.mdl_name
|
44
48
|
end
|
45
49
|
|
50
|
+
def controller_ref
|
51
|
+
self.class.controller_ref
|
52
|
+
end
|
53
|
+
|
46
54
|
# Returns the node in the Hammock routing map corresponding to the (possibly nested) resource handling the current request.
|
47
55
|
def current_hammock_resource
|
48
56
|
nesting_resources = params.keys.map {|k| k.dup.chomp!('_id') }.compact.map(&:pluralize)
|
@@ -63,8 +71,8 @@ module Hammock
|
|
63
71
|
# This is useful for concise nested parameter access. For example, if <tt>params[:account]</tt> is nil:
|
64
72
|
# params[:account][:email] #=> NoMethodError: undefined method `[]' for nil:NilClass
|
65
73
|
# params_for(:account)[:email] #=> nil
|
66
|
-
def params_for
|
67
|
-
params[key] || {}
|
74
|
+
def params_for *keys
|
75
|
+
keys.inject(params) {|acc,key| acc[key] || {} }
|
68
76
|
end
|
69
77
|
|
70
78
|
def nested_params_for resource
|
@@ -97,7 +105,6 @@ module Hammock
|
|
97
105
|
results.map {|records|
|
98
106
|
records.first
|
99
107
|
}.all? {|record|
|
100
|
-
log "nested record #{record.concise_inspect} assigned to @#{record.base_model}."
|
101
108
|
add_nested_entity record
|
102
109
|
instance_variable_set "@#{record.base_model}", record
|
103
110
|
}
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hammock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 9
|
9
|
+
version: 0.5.9
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Ben Hoskings
|
@@ -9,29 +14,38 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-05-12 00:00:00 +10:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rails
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ~>
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 3
|
30
|
+
- 0
|
23
31
|
version: 2.3.0
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: benhoskings-ambitious-activerecord
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ~>
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 1
|
44
|
+
- 3
|
45
|
+
- 7
|
33
46
|
version: 0.1.3.7
|
34
|
-
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
35
49
|
description: ""
|
36
50
|
email: ben@hoskings.net
|
37
51
|
executables: []
|
@@ -109,18 +123,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
123
|
requirements:
|
110
124
|
- - ">="
|
111
125
|
- !ruby/object:Gem::Version
|
126
|
+
segments:
|
127
|
+
- 0
|
112
128
|
version: "0"
|
113
|
-
version:
|
114
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
130
|
requirements:
|
116
131
|
- - ">="
|
117
132
|
- !ruby/object:Gem::Version
|
133
|
+
segments:
|
134
|
+
- 0
|
118
135
|
version: "0"
|
119
|
-
version:
|
120
136
|
requirements: []
|
121
137
|
|
122
138
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.3.
|
139
|
+
rubygems_version: 1.3.6
|
124
140
|
signing_key:
|
125
141
|
specification_version: 3
|
126
142
|
summary: Radically RESTful Rails.
|