Class: ObjectAttorney::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/object_attorney/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.



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

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
  end
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/object_attorney/reflection.rb', line 4

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/object_attorney/reflection.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/object_attorney/reflection.rb', line 4

def options
  @options
end

Instance Method Details

#plural_nameObject



24
25
26
# File 'lib/object_attorney/reflection.rb', line 24

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

#single_nameObject



20
21
22
# File 'lib/object_attorney/reflection.rb', line 20

def single_name
  @single_name ||= options[:single_name] || Helpers.singularize(name)
end