Class: Mongoid::Max::Denormalize::Base
- Inherits:
-
Object
- Object
- Mongoid::Max::Denormalize::Base
- Defined in:
- lib/mongoid/max/denormalize/base.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#inverse_meta ⇒ Object
Returns the value of attribute inverse_meta.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_options ⇒ Object
- #fields_methods ⇒ Object
- #fields_only ⇒ Object
-
#initialize(klass, meta, inverse_meta, fields, options) ⇒ Base
constructor
A new instance of Base.
- #inverse_klass ⇒ Object
- #inverse_relation ⇒ Object
- #relation ⇒ Object
- #unallowed_options ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(klass, meta, inverse_meta, fields, options) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 16 17 18 |
# File 'lib/mongoid/max/denormalize/base.rb', line 10 def initialize(klass, , , fields, ) @klass = klass @meta = @inverse_meta = @fields = fields @options = verify end |
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
8 9 10 |
# File 'lib/mongoid/max/denormalize/base.rb', line 8 def fields @fields end |
#inverse_meta ⇒ Object
Returns the value of attribute inverse_meta.
8 9 10 |
# File 'lib/mongoid/max/denormalize/base.rb', line 8 def @inverse_meta end |
#klass ⇒ Object
Returns the value of attribute klass.
8 9 10 |
# File 'lib/mongoid/max/denormalize/base.rb', line 8 def klass @klass end |
#meta ⇒ Object
Returns the value of attribute meta.
8 9 10 |
# File 'lib/mongoid/max/denormalize/base.rb', line 8 def @meta end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/mongoid/max/denormalize/base.rb', line 8 def @options end |
Class Method Details
.array_code_for(fields) ⇒ Object
67 68 69 |
# File 'lib/mongoid/max/denormalize/base.rb', line 67 def array_code_for(fields) fields.map { |field| ":#{field}" }.join(", ") end |
Instance Method Details
#allowed_options ⇒ Object
37 38 39 |
# File 'lib/mongoid/max/denormalize/base.rb', line 37 def [] end |
#fields_methods ⇒ Object
56 57 58 59 60 |
# File 'lib/mongoid/max/denormalize/base.rb', line 56 def fields_methods @fields_methods ||= fields.select do |field| .klass.fields[field.to_s].nil? end end |
#fields_only ⇒ Object
61 62 63 |
# File 'lib/mongoid/max/denormalize/base.rb', line 61 def fields_only @fields_only ||= fields - fields_methods end |
#inverse_klass ⇒ Object
51 52 53 |
# File 'lib/mongoid/max/denormalize/base.rb', line 51 def inverse_klass .klass end |
#inverse_relation ⇒ Object
48 49 50 |
# File 'lib/mongoid/max/denormalize/base.rb', line 48 def inverse_relation .inverse end |
#relation ⇒ Object
45 46 47 |
# File 'lib/mongoid/max/denormalize/base.rb', line 45 def relation .name end |
#unallowed_options ⇒ Object
41 42 43 |
# File 'lib/mongoid/max/denormalize/base.rb', line 41 def .keys - end |
#verify ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/max/denormalize/base.rb', line 20 def verify # There are fields raise ConfigError.new("Nothing to denormalize", klass, relation) if fields.empty? && .empty? # All fields/methods are well defined fields.each do |field| unless .klass.instance_methods.include? field raise ConfigError.new("Unknown field or method :#{field}", klass, relation) end end # All options are allowed unless .empty? raise ConfigError.new("Unknown or not supported options :#{.first}", klass, relation) end end |