Class: GemBench::GemfileLineTokenizer

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_bench/gemfile_line_tokenizer.rb

Constant Summary collapse

GEM_REGEX =

run against gem lines like: “gem ‘aftership’, # Ruby SDK of AfterShip API.”

/\A\s*gem\s+([^#]*).*\Z/.freeze
GEM_NAME_REGEX =

run against gem lines like: “gem ‘aftership’, # Ruby SDK of AfterShip API.”

/\A\s*gem\s+['"]{1}(?<name>[^'"]*)['"].*\Z/.freeze
VERSION_CONSTRAINT =
/['"]{1}([^'"]*)['"]/.freeze
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC =
lambda { |key|
  /\A\s*[^#]*(?<key1>#{key}: *)['"]{1}(?<value1>[^'"]*)['"]|(?<key2>['"]#{key}['"] *=> *)['"]{1}(?<value2>[^'"]*)['"]|(?<key3>:#{key} *=> *)['"]{1}(?<value3>[^'"]*)['"]/
}
VERSION_PATH =
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC.call("path").freeze
VERSION_GIT =
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC.call("git").freeze
VERSION_GITHUB =
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC.call("github").freeze
VERSION_GIT_REF =
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC.call("ref").freeze
VERSION_GIT_TAG =
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC.call("tag").freeze
VERSION_GIT_BRANCH =
GEMFILE_HASH_CONFIG_KEY_REGEX_PROC.call("branch").freeze
VALID_VERSION_TYPES =
%i[
  constraint
  git_ref
  git_tag
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(all_lines, line, index) ⇒ GemfileLineTokenizer

Returns a new instance of GemfileLineTokenizer.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 28

def initialize(all_lines, line, index)
  @line = line.strip
  @is_gem = self.line.match(GEM_REGEX)
  if is_gem
    @all_lines = all_lines
    @index = index
    @tokens = self.line.split(",")
    determine_name
    if name
      determine_relevant_lines
      determine_version
      @parse_success = true
      @valid = VALID_VERSION_TYPES.include?(version_type)
    else
      noop
    end
  else
    noop
  end
end

Instance Attribute Details

#all_linesObject (readonly)

Returns the value of attribute all_lines.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def all_lines
  @all_lines
end

#indexObject (readonly)

Returns the value of attribute index.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def index
  @index
end

#is_gemObject (readonly)

Returns the value of attribute is_gem.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def is_gem
  @is_gem
end

#lineObject (readonly)

branch is only valid if the branch is not master



21
22
23
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 21

def line
  @line
end

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def name
  @name
end

#parse_successObject (readonly)

Returns the value of attribute parse_success.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def parse_success
  @parse_success
end

#relevant_linesObject (readonly)

Returns the value of attribute relevant_lines.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def relevant_lines
  @relevant_lines
end

#tokensObject (readonly)

Returns the value of attribute tokens.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def tokens
  @tokens
end

#validObject (readonly)

Returns the value of attribute valid.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def valid
  @valid
end

#versionObject (readonly)

version will be a string if it is a normal constraint like ‘~> 1.2.3’ version will be a hash if it is an alternative constraint like: git: “blah/blah”, ref: “shasha”



26
27
28
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 26

def version
  @version
end

#version_typeObject (readonly)

Returns the value of attribute version_type.



22
23
24
# File 'lib/gem_bench/gemfile_line_tokenizer.rb', line 22

def version_type
  @version_type
end