class Gemat::OutDsl

Constants

ALL_SOURCES
ARCHIVED
AUTHORS
CREATED_AT
DEFAULT_COLUMNS
DESCRIPTION

GitHub

DISABLED
DOC_URI

Rubygems

FORKS
GEM_SOURCES
GEM_URI
GITHUB_RESPONSE_SOURCES
INDEX

gem

LANGUAGE
LATEST_VERSION
NAME
NETWORK_COUNT
OPEN_ISSUES_COUNT
REPO_URI
RUBYGEMS_RESPONSE_SOURCES
SIZE
STAR
SUBSCRIBERS
UPDATED_AT
WATCH

Attributes

column_name[RW]
max_length[RW]

Public Class Methods

create(columns, all: nil) click to toggle source
# File lib/out_dsl.rb, line 46
def self.create(columns, all: nil)
  if columns
    new_by_array(columns)
  elsif all
    new_by_array(ALL_SOURCES)
  else
    new_by_array(DEFAULT_COLUMNS)
  end
end
new(column_name) click to toggle source
# File lib/out_dsl.rb, line 56
def initialize(column_name)
  @column_name = column_name

  set_lambda
end
new_by_array(columns) click to toggle source
# File lib/out_dsl.rb, line 42
def self.new_by_array(columns)
  columns.map { |column| new(column) }
end

Public Instance Methods

call(gem) click to toggle source
# File lib/out_dsl.rb, line 62
def call(gem)
  @lambda.call(gem)
end
gem_method(column) click to toggle source
# File lib/out_dsl.rb, line 93
def gem_method(column)
  ->(gem) { gem.send(column) }
end
github_response(column) click to toggle source
# File lib/out_dsl.rb, line 89
def github_response(column)
  ->(gem) { gem.github[column] }
end
rubygems_response(column) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/out_dsl.rb, line 85
def rubygems_response(column)
  ->(gem) { gem.rubygems[column] }
end
set_lambda() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/out_dsl.rb, line 67
    def set_lambda
      case @column_name
      when *RUBYGEMS_RESPONSE_SOURCES
        @lambda = rubygems_response(@column_name)
      when *GITHUB_RESPONSE_SOURCES
        @lambda = github_response(@column_name)
      when *GEM_SOURCES
        @lambda = gem_method(@column_name)
      else
        msg = <<-ERROR.gsub(/^\s+/, '')
          Contain invalid column name `#{@column_name}`!
          valid columns hint: [#{ALL_SOURCES}]
        ERROR
        raise StandardError, msg
      end
    end