Skip to content

Commit

Permalink
[api] require newer xmlhash version
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Oct 1, 2012
1 parent 6b69ba3 commit 3db3287
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 62 deletions.
65 changes: 19 additions & 46 deletions src/activexml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,29 @@
require 'json'
require 'xmlhash'

# adding a function to the ruby hash
class Hash
def elements(name)
unless name.kind_of? String
raise ArgumentError, "expected string"
end
sub = self[name]
return [] unless sub
unless sub.kind_of? Array
if block_given?
yield sub
return
else
return [sub]
end
# adding some more functions to XMLHash
module Xmlhash
class XMLHash
def has_element?(name)
return self.has_key? name.to_s
end
return sub unless block_given?
sub.each do |n|
yield n

def has_attribute?(name)
return self.has_key? name.to_s
end
end

def get(name)
sub = self[name]
return sub if sub
return {}
end

def value(name)
sub = self[name.to_s]
return nil unless sub
return '' if sub.blank? # avoid {}
return sub
end

def has_element?(name)
return self.has_key? name.to_s
end

def has_attribute?(name)
return self.has_key? name.to_s
end

def method_missing( symbol, *args, &block )
if args.size > 0 || !block.nil?
raise RuntimeError, "das geht zuweit #{symbol.inspect}(#{args.inspect})"

def initialize(opts = nil)
self.replace(opts) if opts
end

ActiveXML::Config.logger.debug "method_missing -#{symbol}- #{block.inspect}"
return self[symbol.to_s]
def method_missing( symbol, *args, &block )
if args.size > 0 || !block.nil?
raise RuntimeError, "das geht zuweit #{symbol.inspect}(#{args.inspect})"
end

ActiveXML::Config.logger.debug "method_missing -#{symbol}- #{block.inspect}"
return self[symbol.to_s]
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gem 'exception_notification', '>=2.3'
gem 'yajl-ruby'
gem 'ci_reporter'
gem 'rdoc'
gem 'xmlhash', '>=1.2.2'
gem 'xmlhash', '>=1.3.0'
gem 'fast_xs'
gem 'minitest'
gem 'memcache-client', :require => false
Expand Down
12 changes: 6 additions & 6 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ GEM
daemons (1.1.9)
delayed_job (3.0.3)
activesupport (~> 3.0)
delayed_job_active_record (0.3.2)
activerecord (> 2.1.0)
delayed_job (~> 3.0.0)
delayed_job_active_record (0.3.3)
activerecord (>= 2.1.0, < 4)
delayed_job (~> 3.0)
erubis (2.7.0)
exception_notification (2.6.1)
actionmailer (>= 3.0.4)
Expand All @@ -52,7 +52,7 @@ GEM
treetop (~> 1.4.8)
memcache-client (1.8.5)
mime-types (1.19)
minitest (3.5.0)
minitest (4.0.0)
multi_json (1.3.6)
mysql2 (0.3.11)
nokogiri (1.5.5)
Expand Down Expand Up @@ -99,7 +99,7 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
xmlhash (1.2.4)
xmlhash (1.3.0)
pkg-config
yajl-ruby (1.1.0)

Expand All @@ -120,5 +120,5 @@ DEPENDENCIES
rails (~> 3.2.1)
rdoc
simplecov-rcov
xmlhash (>= 1.2.2)
xmlhash (>= 1.3.0)
yajl-ruby
2 changes: 1 addition & 1 deletion src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.new_from_xml(xml)
request.bs_request_actions << BsRequestAction.new_from_xml_hash(ac)
end if actions

state = hashed.delete("state") || { "name" => "new" }
state = hashed.delete("state") || Xmlhash::XMLHash.new({ "name" => "new" })
request.state = state.delete("name") { raise ArgumentError, "state without name" }
request.state = :declined if request.state.to_s == "rejected"
request.state = :accepted if request.state.to_s == "accept"
Expand Down
2 changes: 1 addition & 1 deletion src/webui/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ gem 'delayed_job_active_record'
gem 'exception_notification', '>=2.3'
gem 'yajl-ruby'
gem 'rdoc'
gem 'xmlhash', '>=1.2.4'
gem 'xmlhash', '>=1.3.0'
gem 'fast_xs'
gem 'memcache-client', :require => false
gem 'jquery-rails'
Expand Down
12 changes: 6 additions & 6 deletions src/webui/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ GEM
cssmin (1.0.2)
delayed_job (3.0.3)
activesupport (~> 3.0)
delayed_job_active_record (0.3.2)
activerecord (> 2.1.0)
delayed_job (~> 3.0.0)
delayed_job_active_record (0.3.3)
activerecord (>= 2.1.0, < 4)
delayed_job (~> 3.0)
erubis (2.7.0)
exception_notification (2.6.1)
actionmailer (>= 3.0.4)
Expand All @@ -56,7 +56,7 @@ GEM
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
jquery-rails (2.1.2)
jquery-rails (2.1.3)
railties (>= 3.1.0, < 5.0)
thor (~> 0.14)
json (1.7.5)
Expand Down Expand Up @@ -132,7 +132,7 @@ GEM
nokogiri (>= 1.2.0)
rack (>= 1.0)
rack-test (>= 0.5.3)
xmlhash (1.2.4)
xmlhash (1.3.0)
pkg-config
yajl-ruby (1.1.0)

Expand Down Expand Up @@ -160,5 +160,5 @@ DEPENDENCIES
sqlite3
uglifier (>= 1.2.2)
webrat (>= 0.7.3)
xmlhash (>= 1.2.4)
xmlhash (>= 1.3.0)
yajl-ruby
3 changes: 2 additions & 1 deletion src/webui/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ def render_error( opt={} )
@exception = opt[:exception] if show_detailed_exceptions?
@api_exception = opt[:api_exception] if show_detailed_exceptions?
logger.debug "ERROR: #{@code}; #{@message}"
logger.debug @exception.backtrace.join("\n") if @exception
if request.xhr?
render :text => @message, :status => @status, :layout => false
else
Expand Down Expand Up @@ -277,7 +278,7 @@ def find_cached(classname, *args)

def find_hashed(classname, *args)
ret = classname.find_cached( *args )
return {} unless ret
return Xmlhash::XMLHash.new({}) unless ret
ret.to_hash
end

Expand Down

0 comments on commit 3db3287

Please sign in to comment.