From ea3223e6e66513fe17602d5a38926b4109a61210 Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Tue, 3 Dec 2013 14:32:27 +0200 Subject: [PATCH 1/5] showing ancestors in documentation for activerecord objects --- app/helpers/washout_builder_helper.rb | 25 ++++++++++++++++++++----- lib/washout_builder/dispatcher.rb | 1 + lib/washout_builder/version.rb | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index 63dbbe3..830aecc 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -21,7 +21,21 @@ def get_complex_class_name(p, defined = []) def get_nested_complex_types(param, defined) defined = [] if defined.blank? complex_class = get_complex_class_name(param, defined) - defined << {:class =>complex_class, :obj => param} unless complex_class.nil? + if param.classified? + param_class = complex_class.constantize + ancestors = param_class.ancestors - param_class.included_modules + ancestors.delete_if{ |x| x.to_s == complex_class || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" } + unless ancestors.blank? + ancestors.each do |ancestor_class| + ancestor_structure = ancestor_class.columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } + ancestor_structure = {ancestor_class.to_s.downcase => ancestor_structure} + defined << {:class =>ancestor_class.to_s, :obj => WashoutBuilder::Param.parse_def(@soap_config,ancestor_structure, true)[0]} + end + end + defined << {:class =>complex_class, :obj => param, :ancestors => ancestors} unless complex_class.nil? + else + defined << {:class =>complex_class, :obj => param} unless complex_class.nil? + end if param.is_complex? c_names = [] param.map.each do |obj| @@ -57,21 +71,22 @@ def get_soap_action_names(map) def create_html_complex_types(xml, types) types.each do |hash| - create_complex_type_html(xml, hash[:obj], hash[:class]) + create_complex_type_html(xml, hash[:obj], hash[:class], hash[:ancestors]) end end - def create_complex_type_html(xml, param, class_name) + def create_complex_type_html(xml, param, class_name, ancestors) unless param.blank? xml.a( "name" => "#{class_name}") { } - xml.h3 "#{class_name}" + xml.h3 { |pre| pre << "#{class_name} #{ancestors.blank? ? "" : "(extends #{ancestors[0].to_s.classify} )" } " } if param.is_a?(WashoutBuilder::Param) xml.ul("class" => "pre") { - + param.map.each do |element| + element.type = "string" if element.type == "text" # raise YAML::dump(element) if class_name.include?("ype") and element.name == "members" xml.li { |pre| if WashoutBuilder::Type::BASIC_TYPES.include?(element.type) diff --git a/lib/washout_builder/dispatcher.rb b/lib/washout_builder/dispatcher.rb index 369017f..5590d1f 100644 --- a/lib/washout_builder/dispatcher.rb +++ b/lib/washout_builder/dispatcher.rb @@ -13,6 +13,7 @@ def _generate_doc @name = controller_path.gsub('/', '_') @service = self.class.name.underscore.gsub("_controller", "").camelize @endpoint = @namespace.gsub("/wsdl", "/action") + @soap_config = soap_config render :template => "wash_with_html/doc", :layout => false, :content_type => 'text/html' diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 268db9a..7025862 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.4.4" + VERSION = "0.4.5" end From 0953d92cad43d26834cd3108020c2099b5499fba Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Tue, 3 Dec 2013 15:21:34 +0200 Subject: [PATCH 2/5] fix showing ancestors --- app/helpers/washout_builder_helper.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index 830aecc..4ebec66 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -17,22 +17,27 @@ def get_complex_class_name(p, defined = []) return complex_class end - - def get_nested_complex_types(param, defined) - defined = [] if defined.blank? - complex_class = get_complex_class_name(param, defined) - if param.classified? - param_class = complex_class.constantize + + def get_class_ancestors(class_name, defined) + param_class = class_name.is_a?(Class) ? class_name : class_name.constantize ancestors = param_class.ancestors - param_class.included_modules - ancestors.delete_if{ |x| x.to_s == complex_class || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" } + ancestors.delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" } unless ancestors.blank? ancestors.each do |ancestor_class| - ancestor_structure = ancestor_class.columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } - ancestor_structure = {ancestor_class.to_s.downcase => ancestor_structure} - defined << {:class =>ancestor_class.to_s, :obj => WashoutBuilder::Param.parse_def(@soap_config,ancestor_structure, true)[0]} + ancestor_structure = {ancestor_class.to_s.downcase => ancestor_class.columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } } + top_ancestors = get_class_ancestors(ancestor_class, defined) + defined << {:class =>ancestor_class.to_s, :obj => WashoutBuilder::Param.parse_def(@soap_config,ancestor_structure)[0] , :ancestors => top_ancestors } end end - defined << {:class =>complex_class, :obj => param, :ancestors => ancestors} unless complex_class.nil? + ancestors + end + + + def get_nested_complex_types(param, defined) + defined = [] if defined.blank? + complex_class = get_complex_class_name(param, defined) + if param.classified? + defined << {:class =>complex_class, :obj => param, :ancestors => get_class_ancestors(complex_class, defined)} unless complex_class.nil? else defined << {:class =>complex_class, :obj => param} unless complex_class.nil? end From 10df890fb4082927a49a39253f9a9bbae06ce07a Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Tue, 3 Dec 2013 15:26:17 +0200 Subject: [PATCH 3/5] fix showing ancestors --- app/helpers/washout_builder_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index 4ebec66..3ad82df 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -21,7 +21,7 @@ def get_complex_class_name(p, defined = []) def get_class_ancestors(class_name, defined) param_class = class_name.is_a?(Class) ? class_name : class_name.constantize ancestors = param_class.ancestors - param_class.included_modules - ancestors.delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" } + ancestors.delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "WashOut::Type" } unless ancestors.blank? ancestors.each do |ancestor_class| ancestor_structure = {ancestor_class.to_s.downcase => ancestor_class.columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } } @@ -36,7 +36,7 @@ def get_class_ancestors(class_name, defined) def get_nested_complex_types(param, defined) defined = [] if defined.blank? complex_class = get_complex_class_name(param, defined) - if param.classified? + if param.classified? defined << {:class =>complex_class, :obj => param, :ancestors => get_class_ancestors(complex_class, defined)} unless complex_class.nil? else defined << {:class =>complex_class, :obj => param} unless complex_class.nil? From 1d24ddc7f93b65dec4f0f7f31fdf89bc778ddebe Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Tue, 3 Dec 2013 15:52:27 +0200 Subject: [PATCH 4/5] finalize ancestor displaying --- app/helpers/washout_builder_helper.rb | 54 ++++++++++++++++++++------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/app/helpers/washout_builder_helper.rb b/app/helpers/washout_builder_helper.rb index 3ad82df..b137b1f 100644 --- a/app/helpers/washout_builder_helper.rb +++ b/app/helpers/washout_builder_helper.rb @@ -18,18 +18,46 @@ def get_complex_class_name(p, defined = []) end - def get_class_ancestors(class_name, defined) - param_class = class_name.is_a?(Class) ? class_name : class_name.constantize - ancestors = param_class.ancestors - param_class.included_modules - ancestors.delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "WashOut::Type" } - unless ancestors.blank? - ancestors.each do |ancestor_class| - ancestor_structure = {ancestor_class.to_s.downcase => ancestor_class.columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } } - top_ancestors = get_class_ancestors(ancestor_class, defined) - defined << {:class =>ancestor_class.to_s, :obj => WashoutBuilder::Param.parse_def(@soap_config,ancestor_structure)[0] , :ancestors => top_ancestors } - end - end - ancestors + def get_param_structure(param) + param.map.inject({}) {|h,element| h[element.name] = element.type;h } + end + + + def remove_type_inheritable_elements(param, keys) + param.map.delete_if{|element| keys.include?(element.name) } + end + + + def same_structure_as_ancestor?(param, ancestor) + param_structure = get_param_structure(param) + ancestor_structure = get_param_structure(ancestor) + if param_structure.keys == ancestor_structure.keys + return true + else + remove_type_inheritable_elements(param, ancestor_structure.keys) + return false + end + end + + + + + def get_class_ancestors(param,class_name, defined) + bool_the_same = false + param_class = class_name.is_a?(Class) ? class_name : class_name.constantize + ancestors = param_class.ancestors - param_class.included_modules + ancestors.delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "WashOut::Type" } + unless ancestors.blank? + ancestor_class = ancestors[0] + ancestor_structure = {ancestor_class.to_s.downcase => ancestor_class.columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } } + ancestor_object = WashoutBuilder::Param.parse_def(@soap_config,ancestor_structure)[0] + bool_the_same = same_structure_as_ancestor?(param, ancestor_object) + unless bool_the_same + top_ancestors = get_class_ancestors(ancestor_class, defined) + defined << {:class =>ancestor_class.to_s, :obj =>ancestor_object , :ancestors => top_ancestors } + end + end + ancestors unless bool_the_same end @@ -37,7 +65,7 @@ def get_nested_complex_types(param, defined) defined = [] if defined.blank? complex_class = get_complex_class_name(param, defined) if param.classified? - defined << {:class =>complex_class, :obj => param, :ancestors => get_class_ancestors(complex_class, defined)} unless complex_class.nil? + defined << {:class =>complex_class, :obj => param, :ancestors => get_class_ancestors(param, complex_class, defined)} unless complex_class.nil? else defined << {:class =>complex_class, :obj => param} unless complex_class.nil? end From 6719100cdddda99d2c47f1ea0056810b31b66a5f Mon Sep 17 00:00:00 2001 From: bogdanRada Date: Tue, 3 Dec 2013 15:53:08 +0200 Subject: [PATCH 5/5] version tick --- lib/washout_builder/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 7025862..a469221 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,3 +1,3 @@ module WashoutBuilder - VERSION = "0.4.5" + VERSION = "0.5.0" end