aboutsummaryrefslogtreecommitdiffstats
path: root/actionwebservice/lib/action_web_service
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-03-26 21:26:13 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-03-26 21:26:13 +0000
commitc4f1979db5b69f85b1e51bfa9a3e119bc71a4e24 (patch)
tree9ca497d7946eeb2884ec29474198c1ad6799f2e3 /actionwebservice/lib/action_web_service
parent77c8e3a0fd32e736575edce503b2e9f891193f9e (diff)
downloadrails-c4f1979db5b69f85b1e51bfa9a3e119bc71a4e24.tar.gz
rails-c4f1979db5b69f85b1e51bfa9a3e119bc71a4e24.tar.bz2
rails-c4f1979db5b69f85b1e51bfa9a3e119bc71a4e24.zip
Make ActiveWebService::Struct type reloadable. Fix scaffolding action when one of the members of a structural type has date or time type. Remove extra index hash when generating scaffold html for parameters of structural type (closes #4374) [joe@mjg2.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4054 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionwebservice/lib/action_web_service')
-rw-r--r--actionwebservice/lib/action_web_service/casting.rb3
-rw-r--r--actionwebservice/lib/action_web_service/scaffolding.rb43
-rw-r--r--actionwebservice/lib/action_web_service/struct.rb3
3 files changed, 24 insertions, 25 deletions
diff --git a/actionwebservice/lib/action_web_service/casting.rb b/actionwebservice/lib/action_web_service/casting.rb
index 8ccc7797ac..4fb5a8db25 100644
--- a/actionwebservice/lib/action_web_service/casting.rb
+++ b/actionwebservice/lib/action_web_service/casting.rb
@@ -96,10 +96,13 @@ module ActionWebService # :nodoc:
when :float
Float(value)
when :time
+ value = "#{value['2']}/#{value['3']}/#{value['1']} #{value['4']}:#{value['5']}:#{value['6']}" if value.kind_of?(Hash)
Time.parse(value.to_s)
when :date
+ value = "#{value['2']}/#{value['3']}/#{value['1']}" if value.kind_of?(Hash)
Date.parse(value.to_s)
when :datetime
+ value = "#{value['2']}/#{value['3']}/#{value['1']} #{value['4']}:#{value['5']}:#{value['6']}" if value.kind_of?(Hash)
DateTime.parse(value.to_s)
end
end
diff --git a/actionwebservice/lib/action_web_service/scaffolding.rb b/actionwebservice/lib/action_web_service/scaffolding.rb
index 21689da990..e0e00d831b 100644
--- a/actionwebservice/lib/action_web_service/scaffolding.rb
+++ b/actionwebservice/lib/action_web_service/scaffolding.rb
@@ -69,21 +69,9 @@ module ActionWebService
@protocol.register_api(@scaffold_service.api)
post_params = params['method_params'] ? params['method_params'].dup : nil
params = []
- if @scaffold_method.expects
- @scaffold_method.expects.each_with_index do |spec, i|
- case spec.type
- when :date
- date = post_params[i.to_s]
- params << (date['2'] + '/' + date['3'] + '/' + date['1'])
- when :datetime, :time
- date = post_params[i.to_s]
- params << (date['2'] + '/' + date['3'] + '/' + date['1'] + ' ' +
- date['4'] + ':' + date['5'] + ':' + date['6'])
- else
- params << post_params[i.to_s]
- end
- end
- end
+ @scaffold_method.expects.each_with_index do |spec, i|
+ params << post_params[i.to_s]
+ end if @scaffold_method.expects
params = @scaffold_method.cast_expects(params)
method_name = public_method_name(@scaffold_service.name, @scaffold_method.public_name)
@method_request_xml = @protocol.encode_request(method_name, params, @scaffold_method.expects)
@@ -176,11 +164,12 @@ module ActionWebService
end
module Helpers # :nodoc:
- def method_parameter_input_fields(method, type, field_name_base, idx)
+ def method_parameter_input_fields(method, type, field_name_base, idx, was_structured=false)
if type.array?
return content_tag('em', "Typed array input fields not supported yet (#{type.name})")
end
if type.structured?
+ return content_tag('em', "Nested structural types not supported yet (#{type.name})") if was_structured
parameters = ""
type.each_member do |member_name, member_type|
label = method_parameter_label(member_name, member_type)
@@ -188,7 +177,8 @@ module ActionWebService
method,
member_type,
"#{field_name_base}[#{idx}][#{member_name}]",
- idx)
+ idx,
+ true)
if member_type.custom?
parameters << content_tag('li', label)
parameters << content_tag('ul', nested_content)
@@ -198,31 +188,34 @@ module ActionWebService
end
content_tag('ul', parameters)
else
+ # If the data source was structured previously we already have the index set
+ field_name_base = "#{field_name_base}[#{idx}]" unless was_structured
+
case type.type
when :int
- text_field_tag "#{field_name_base}[#{idx}]"
+ text_field_tag "#{field_name_base}"
when :string
- text_field_tag "#{field_name_base}[#{idx}]"
+ text_field_tag "#{field_name_base}"
when :base64
- text_area_tag "#{field_name_base}[#{idx}]", nil, :size => "40x5"
+ text_area_tag "#{field_name_base}", nil, :size => "40x5"
when :bool
- radio_button_tag("#{field_name_base}[#{idx}]", "true") + " True" +
- radio_button_tag("#{field_name_base}[#{idx}]", "false") + "False"
+ radio_button_tag("#{field_name_base}", "true") + " True" +
+ radio_button_tag("#{field_name_base}", "false") + "False"
when :float
- text_field_tag "#{field_name_base}[#{idx}]"
+ text_field_tag "#{field_name_base}"
when :time, :datetime
time = Time.now
i = 0
%w|year month day hour minute second|.map do |name|
i += 1
- send("select_#{name}", time, :prefix => "#{field_name_base}[#{idx}][#{i}]", :discard_type => true)
+ send("select_#{name}", time, :prefix => "#{field_name_base}[#{i}]", :discard_type => true)
end.join
when :date
date = Date.today
i = 0
%w|year month day|.map do |name|
i += 1
- send("select_#{name}", date, :prefix => "#{field_name_base}[#{idx}][#{i}]", :discard_type => true)
+ send("select_#{name}", date, :prefix => "#{field_name_base}[#{i}]", :discard_type => true)
end.join
end
end
diff --git a/actionwebservice/lib/action_web_service/struct.rb b/actionwebservice/lib/action_web_service/struct.rb
index 536207aa95..d065dae03b 100644
--- a/actionwebservice/lib/action_web_service/struct.rb
+++ b/actionwebservice/lib/action_web_service/struct.rb
@@ -19,6 +19,9 @@ module ActionWebService
# Active Record model classes are already implicitly supported in method
# signatures.
class Struct
+ # Action WebService Struct subclasses should be reloaded by the dispatcher in Rails
+ # when Dependencies.mechanism = :load.
+ include Reloadable::Subclasses
# If a Hash is given as argument to an ActionWebService::Struct constructor,
# it can contain initial values for the structure member.