module ActionBlocks::GeneratorHelper
Protected Instance Methods
association_class_exists_with_this_name?(association_name)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 119 def association_class_exists_with_this_name?(association_name) klass = Module.const_get(association_name.to_s.singularize.classify) return klass.is_a?(Class) rescue NameError return false end
attachment_names(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 109 def attachment_names(cname=nil) if respond_to?(:attributes) && attributes.present? attributes.select{|a| a.attachment?}.map(&:name) else cn = cname || class_name names = cn.constantize.content_columns.select{|a| a.name.to_s =~ /_file_name\Z/}.map{|a| a.name.to_s.gsub(/_file_name\Z/, "")} names end end
belongs_to_association_details(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 61 def belongs_to_association_details(cname=nil) if respond_to?(:attributes) && attributes.present? attributes.select{|a| a.reference?} else cn = cname || class_name begin cn.constantize.reflect_on_all_associations(:belongs_to) rescue [] end end end
belongs_to_associations(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 48 def belongs_to_associations(cname=nil) if respond_to?(:attributes) && attributes.present? attributes.select{|a| a.reference?}.map(&:name) else cn = cname || class_name begin cn.constantize.reflect_on_all_associations(:belongs_to).map(&:name) rescue [] end end end
clean(c)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 103 def clean(c) c = c.to_s return nil if c.in?(%w(updated_at created_at deleted deleted_at)) || c =~ /_file_size|_updated_at|_content_type/ c.to_s.gsub('_file_name','') end
collection_name(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 10 def collection_name(cname=nil) cn = cname || class_name collectionize(cn) end
collectionize(s)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 15 def collectionize(s) s.to_s.underscore.pluralize end
content_column_details(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 90 def content_column_details(cname=nil) if respond_to?(:attributes) && attributes.present? attributes.reject{|a| a.reference?} else cn = cname || class_name begin cn.constantize.content_columns rescue [] end end end
content_columns(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 74 def content_columns(cname=nil) if respond_to?(:attributes) && attributes.present? cols = attributes.reject{|a| a.reference?}.map(&:name).map{|n| clean(n)}.compact cols else cn = cname || class_name begin cols = cn.constantize.content_columns.map(&:name).map {|c| clean(c)}.compact cols rescue => ex puts ex.message [] end end end
field_content_columns()
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 126 def field_content_columns if options.fields && options.fields.length > 0 return options.fields & content_columns else return content_columns end end
has_many_association_details(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 33 def has_many_association_details(cname=nil) cn = cname || class_name cn.constantize.reflect_on_all_associations(:has_many).select {|hm| hm.name.downcase != 'versions'} end
has_many_associations(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 28 def has_many_associations(cname=nil) cn = cname || class_name cn.constantize.reflect_on_all_associations(:has_many).map(&:name).select {|hm| hm.downcase != 'versions'} end
has_many_associations?(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 23 def has_many_associations?(cname=nil) cn = cname || class_name cn.constantize.reflect_on_all_associations(:has_many).map(&:name).length > 0 end
has_one_association_details(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 43 def has_one_association_details(cname=nil) cn = cname || class_name cn.constantize.reflect_on_all_associations(:has_one) end
has_one_associations(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 38 def has_one_associations(cname=nil) cn = cname || class_name cn.constantize.reflect_on_all_associations(:has_one).map(&:name) end
variable(cname=nil)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 5 def variable(cname=nil) cn = cname || class_name variableize(cn) end
variableize(s)
click to toggle source
# File lib/action_blocks/generator_helper.rb, line 19 def variableize(s) s.to_s.underscore.singularize end