Sha256: 3b9939b6adcca414d42382f010a9ac5bbe6f509e551ebe63a664fcf7758ccefa

Contents?: true

Size: 902 Bytes

Versions: 34

Compression:

Stored size: 902 Bytes

Contents

module ObjectAttorney

  class Reflection
    attr_reader :name, :klass, :options

    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

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

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

    private ################################# private

    def klass_default(class_name)
      if Helpers.plural?(class_name)
        class_name.to_s.singularize.camelize
      else
        class_name.to_s.camelize
      end
    end

  end

end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
object_attorney-2.10.12 lib/object_attorney/reflection.rb
object_attorney-2.10.11 lib/object_attorney/reflection.rb
object_attorney-2.10.10 lib/object_attorney/reflection.rb
object_attorney-2.10.9 lib/object_attorney/reflection.rb
object_attorney-2.10.7 lib/object_attorney/reflection.rb
object_attorney-2.10.6 lib/object_attorney/reflection.rb
object_attorney-2.10.5 lib/object_attorney/reflection.rb
object_attorney-2.10.3 lib/object_attorney/reflection.rb
object_attorney-2.10.2 lib/object_attorney/reflection.rb
object_attorney-2.10.1 lib/object_attorney/reflection.rb
object_attorney-2.9.4 lib/object_attorney/reflection.rb
object_attorney-2.9.3 lib/object_attorney/reflection.rb
object_attorney-2.9.2 lib/object_attorney/reflection.rb
object_attorney-2.9.0 lib/object_attorney/reflection.rb
object_attorney-2.8.1 lib/object_attorney/reflection.rb
object_attorney-2.8.0 lib/object_attorney/reflection.rb
object_attorney-2.6.12 lib/object_attorney/reflection.rb
object_attorney-2.6.11 lib/object_attorney/reflection.rb
object_attorney-2.6.10 lib/object_attorney/reflection.rb
object_attorney-2.6.9 lib/object_attorney/reflection.rb