Class: Gemat::OutDsl
- Inherits:
-
Object
- Object
- Gemat::OutDsl
- Defined in:
- lib/out_dsl.rb
Constant Summary collapse
- INDEX =
gem
'index'
- NAME =
'name'
- REPO_URI =
'repo_uri'
- GEM_URI =
'gem_uri'
- DOC_URI =
Rubygems
'documentation_uri'
- LATEST_VERSION =
'version'
- AUTHORS =
'authors'
- DESCRIPTION =
GitHub
'description'
- CREATED_AT =
'created_at'
- UPDATED_AT =
'updated_at'
- SIZE =
'size'
- STAR =
'stargazers_count'
- WATCH =
'watchers_count'
- FORKS =
'forks'
- LANGUAGE =
'language'
- ARCHIVED =
'archived'
- DISABLED =
'disabled'
- OPEN_ISSUES_COUNT =
'open_issues_count'
- NETWORK_COUNT =
'network_count'
- SUBSCRIBERS =
'subscribers_count'
- DEFAULT_COLUMNS =
[INDEX, NAME, REPO_URI, DOC_URI, SIZE, STAR, CREATED_AT, UPDATED_AT].freeze
- RUBYGEMS_RESPONSE_SOURCES =
[NAME, DOC_URI, GEM_URI, LATEST_VERSION, AUTHORS].freeze
- GITHUB_RESPONSE_SOURCES =
[DESCRIPTION, CREATED_AT, UPDATED_AT, SIZE, STAR, WATCH, FORKS, LANGUAGE, ARCHIVED, DISABLED, OPEN_ISSUES_COUNT, NETWORK_COUNT, SUBSCRIBERS].freeze
- GEM_SOURCES =
[INDEX, REPO_URI].freeze
- ALL_SOURCES =
[].concat(GEM_SOURCES, RUBYGEMS_RESPONSE_SOURCES, GITHUB_RESPONSE_SOURCES).freeze
Instance Attribute Summary collapse
-
#column_name ⇒ Object
Returns the value of attribute column_name.
-
#max_length ⇒ Object
Returns the value of attribute max_length.
Class Method Summary collapse
Instance Method Summary collapse
- #call(gem) ⇒ Object
- #gem_method(column) ⇒ Object
- #github_response(column) ⇒ Object
-
#initialize(column_name) ⇒ OutDsl
constructor
A new instance of OutDsl.
-
#rubygems_response(column) ⇒ Object
rubocop:enable Metrics/MethodLength.
-
#set_lambda ⇒ Object
rubocop:disable Metrics/MethodLength.
Constructor Details
#initialize(column_name) ⇒ OutDsl
Returns a new instance of OutDsl.
56 57 58 59 60 |
# File 'lib/out_dsl.rb', line 56 def initialize(column_name) @column_name = column_name set_lambda end |
Instance Attribute Details
#column_name ⇒ Object
Returns the value of attribute column_name.
40 41 42 |
# File 'lib/out_dsl.rb', line 40 def column_name @column_name end |
#max_length ⇒ Object
Returns the value of attribute max_length.
40 41 42 |
# File 'lib/out_dsl.rb', line 40 def max_length @max_length end |
Class Method Details
.create(columns, all: nil) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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_by_array(columns) ⇒ Object
42 43 44 |
# File 'lib/out_dsl.rb', line 42 def self.new_by_array(columns) columns.map { |column| new(column) } end |
Instance Method Details
#call(gem) ⇒ Object
62 63 64 |
# File 'lib/out_dsl.rb', line 62 def call(gem) @lambda.call(gem) end |
#gem_method(column) ⇒ Object
93 94 95 |
# File 'lib/out_dsl.rb', line 93 def gem_method(column) ->(gem) { gem.send(column) } end |
#github_response(column) ⇒ Object
89 90 91 |
# File 'lib/out_dsl.rb', line 89 def github_response(column) ->(gem) { gem.github[column] } end |
#rubygems_response(column) ⇒ Object
rubocop:enable Metrics/MethodLength
85 86 87 |
# File 'lib/out_dsl.rb', line 85 def rubygems_response(column) ->(gem) { gem.rubygems[column] } end |
#set_lambda ⇒ Object
rubocop:disable Metrics/MethodLength
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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 |