Class: Reporter::Scope::ReferenceScope
- Inherits:
-
Base
- Object
- Base
- Reporter::Scope::ReferenceScope
- Defined in:
- lib/reporter/scope/reference_scope.rb
Class Method Summary collapse
Instance Method Summary collapse
- #apply_on(source) ⇒ Object
- #change(object) ⇒ Object
- #group_object ⇒ Object
- #human_name ⇒ Object
-
#initialize(scoping, name, data_source, *args) ⇒ ReferenceScope
constructor
A new instance of ReferenceScope.
- #iterate(items, data_set, &block) ⇒ Object
- #limit=(object_or_array) ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(scoping, name, data_source, *args) ⇒ ReferenceScope
Returns a new instance of ReferenceScope.
3 4 5 6 7 8 9 |
# File 'lib/reporter/scope/reference_scope.rb', line 3 def initialize scoping, name, data_source, *args mappings = args. mappings = create_mappings_for_object_type(data_source, args.first, mappings) if args.first super scoping, data_source, name, mappings @limiter = nil @id_collection = nil end |
Class Method Details
.possible_scopes(sources) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/reporter/scope/reference_scope.rb', line 61 def self.possible_scopes sources results = [] # check reflections reflection_references = nil sources.each do |source| relations = source.relations_to_objects relation_pool = relations.keys + [source.active_record] reflection_references = reflection_references ? (reflection_references & relation_pool) : relation_pool end (reflection_references || []).each do |reflection_object| result_hash = { :type => :reference, :match => :loose, :object => reflection_object } sources.each do |source| fields = [] fields << "id" if (source.active_record == reflection_object) fields += source.relations_to_objects[reflection_object] || [] result_hash[source.model_name] = fields end results << result_hash end #Rails.logger.info reflection_references.inspect results end |
Instance Method Details
#apply_on(source) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/reporter/scope/reference_scope.rb', line 33 def apply_on source raise "No mapped column for source #{source}" unless mappings.has_key? source.name reference = mappings[source.name] limiter = group_object || @limiter if limiter q, values = limit_through_association source, reference, limiter source.where(q, values) else source end end |
#change(object) ⇒ Object
23 24 25 |
# File 'lib/reporter/scope/reference_scope.rb', line 23 def change object scoping.serialize_scope name, item end |
#group_object ⇒ Object
15 16 17 |
# File 'lib/reporter/scope/reference_scope.rb', line 15 def group_object scoping.unserialize_scope(name) end |
#human_name ⇒ Object
27 28 29 30 31 |
# File 'lib/reporter/scope/reference_scope.rb', line 27 def human_name limiter = group_object || @limiter return limiter.collect { |item| human_name_for item }.to_sentence if limiter.is_a? Enumerable human_name_for limiter end |
#iterate(items, data_set, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/reporter/scope/reference_scope.rb', line 46 def iterate items, data_set, &block items ||= @limiter if items.is_a? Enumerable items.each do |item| scoping.serialize_scope name, item yield data_set.get_row end scoping.serialize_scope name, nil else scoping.serialize_scope name, items yield data_set.get_row scoping.serialize_scope name, nil end end |
#limit=(object_or_array) ⇒ Object
11 12 13 |
# File 'lib/reporter/scope/reference_scope.rb', line 11 def limit= object_or_array @limiter = object_or_array end |
#value ⇒ Object
19 20 21 |
# File 'lib/reporter/scope/reference_scope.rb', line 19 def value group_object || @limiter end |