Module: Iord::ResourceInfo
Instance Method Summary collapse
- #action_path ⇒ Object
- #build_resource_attribute_names(klass) ⇒ Object
- #build_resource_info ⇒ Object
- #collection_name ⇒ Object
- #resource_attribute_names ⇒ Object
- #resource_class ⇒ Object
- #resource_name ⇒ Object
- #resource_name_u ⇒ Object
- #resource_path ⇒ Object
Instance Method Details
#action_path ⇒ Object
47 48 49 50 |
# File 'lib/iord/resource_info.rb', line 47 def action_path build_resource_info unless @action_path @action_path end |
#build_resource_attribute_names(klass) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/iord/resource_info.rb', line 92 def build_resource_attribute_names(klass) attribute_names = klass.attribute_names.map{|x| x == '_id' ? 'id' : x} klass.relations.each do |name, relation| case relation.macro when :embeds_one, :embeds_many unless relation.cyclic? || klass.name == relation.class_name = build_resource_attribute_names(relation.class_name.constantize) attribute_names += .map{|attribute| "#{name}.#{attribute}"} end end end attribute_names end |
#build_resource_info ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/iord/resource_info.rb', line 57 def build_resource_info return if @resource_class controller_name = self.class.name[0..-11] namespace = String.new if self.class.resource_namespace.is_a? Module namespace = self.class.resource_namespace.to_s + '::' elsif self.class.resource_namespace namespace = controller_name[0..controller_name.rindex(':')] if controller_name.rindex(':') end class_name = default(:resource_class) class_name ||= self.class.controller_name.camelize class_name = class_name.to_s @collection_name = class_name.humanize resource_class = class_name.singularize @resource_name = resource_class.humanize @resource_name_u = resource_class.underscore @resource_class = (namespace + resource_class).constantize @action_path = request.path[1..-1].split('/'). reject { |x| x=~ /^(#{params[:action]}|[a-f0-9]+(\.#{params[:format]})?)$/ }. map { |x| x.singularize }. join('_').pluralize @resource_path = Array.new if controller_path.rindex('/') path = controller_path[0..controller_path.rindex('/')-1] @resource_path = path.split('/').map { |i| i.to_sym } end #@resource_attribute_names = @resource_class.attribute_names.map { |x| x == "_id" ? "id" : x } @resource_attribute_names = build_resource_attribute_names(@resource_class) end |
#collection_name ⇒ Object
37 38 39 40 |
# File 'lib/iord/resource_info.rb', line 37 def collection_name build_resource_info unless @collection_name @collection_name end |
#resource_attribute_names ⇒ Object
52 53 54 55 |
# File 'lib/iord/resource_info.rb', line 52 def resource_attribute_names build_resource_info unless @resource_attribute_names @resource_attribute_names end |
#resource_class ⇒ Object
22 23 24 25 |
# File 'lib/iord/resource_info.rb', line 22 def resource_class build_resource_info unless @resource_class @resource_class end |
#resource_name ⇒ Object
27 28 29 30 |
# File 'lib/iord/resource_info.rb', line 27 def resource_name build_resource_info unless @resource_name @resource_name end |
#resource_name_u ⇒ Object
32 33 34 35 |
# File 'lib/iord/resource_info.rb', line 32 def resource_name_u build_resource_info unless @resource_name_u @resource_name_u end |
#resource_path ⇒ Object
42 43 44 45 |
# File 'lib/iord/resource_info.rb', line 42 def resource_path build_resource_info unless @resource_path @resource_path end |