Sha256: e258b395b892d16c1513d32966c3a6d3e90ad50dbdc5a3572f3c631e1ee5e0f2

Contents?: true

Size: 787 Bytes

Versions: 11

Compression:

Stored size: 787 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)
      @klass = @klass.constantize if @klass.is_a?(String)
    end

    def single_name
      @single_name ||= options[:single_name] || name.to_s.singularize
    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

11 entries across 11 versions & 1 rubygems

Version Path
object_attorney-2.2.8 lib/object_attorney/reflection.rb
object_attorney-2.2.7 lib/object_attorney/reflection.rb
object_attorney-2.2.6 lib/object_attorney/reflection.rb
object_attorney-2.2.5 lib/object_attorney/reflection.rb
object_attorney-2.2.4 lib/object_attorney/reflection.rb
object_attorney-2.2.3 lib/object_attorney/reflection.rb
object_attorney-2.2.2 lib/object_attorney/reflection.rb
object_attorney-2.2.1 lib/object_attorney/reflection.rb
object_attorney-2.1.3 lib/object_attorney/reflection.rb
object_attorney-2.1.2 lib/object_attorney/reflection.rb
object_attorney-2.1.1 lib/object_attorney/reflection.rb