Class: SmoothOperator::Associations::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/smooth_operator/associations/reflection.rb

Direct Known Subclasses

AssociationReflection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, options) ⇒ Reflection

Returns a new instance of Reflection.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/smooth_operator/associations/reflection.rb', line 7

def initialize(class_name, options)
  options = options.is_a?(Hash) ? options : {}

  @name, @options = class_name, options

  @klass = options[:class_name] || klass_default(@name)

  if options.include?(:class_name) && options[:class_name].nil?
    @klass = nil
  elsif @klass.is_a?(String)
    @klass = @klass.constantize rescue OpenStruct
  end
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/smooth_operator/associations/reflection.rb', line 5

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/smooth_operator/associations/reflection.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/smooth_operator/associations/reflection.rb', line 5

def options
  @options
end

Instance Method Details

#plural_nameObject



25
26
27
# File 'lib/smooth_operator/associations/reflection.rb', line 25

def plural_name
  @plural_name ||= options[:plural_name] || name.to_s.pluralize
end

#single_nameObject



21
22
23
# File 'lib/smooth_operator/associations/reflection.rb', line 21

def single_name
  @single_name ||= options[:single_name] || name.to_s.singularize
end