Class: ConvenientService::Examples::Rails::Gemfile::Services::ParseContent
- Inherits:
-
Object
- Object
- ConvenientService::Examples::Rails::Gemfile::Services::ParseContent
- Includes:
- RailsService::Config
- Defined in:
- lib/convenient_service/examples/rails/gemfile/services/parse_content.rb
Constant Summary collapse
- RUBY_REGEX =
/\A\s*ruby/
- SOURCE_REGEX =
/\A\s*source/
- GIT_SOURCE_REGEX =
/\A\s*git_source/
- GROUP_REGEX =
/\A\s*group/
- GEM_REGEX =
/\A\s*gem/
- BLOCK_END_REGEX =
/\A\s*end/
- ENV_SCAN_REGEX =
/:(\w+)/
Instance Method Summary collapse
Instance Method Details
#parse_content ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/convenient_service/examples/rails/gemfile/services/parse_content.rb', line 54 def parse_content hash = ::Hash.new { |h, k| h[k] = [] } ::StringIO.open(content) do |io| envs = [] until io.eof? line = io.readline.rstrip case line when RUBY_REGEX hash[:ruby] << line when SOURCE_REGEX hash[:source] << line when GIT_SOURCE_REGEX hash[:git_source] << line when GROUP_REGEX envs = line.scan(ENV_SCAN_REGEX).map(&:first).map(&:to_sym) when GEM_REGEX hash[:gems] << {envs: envs, line: line.lstrip} when BLOCK_END_REGEX envs = [] else hash[:rest] << line end end end hash end |
#result ⇒ Object
50 51 52 |
# File 'lib/convenient_service/examples/rails/gemfile/services/parse_content.rb', line 50 def result success(parsed_content: parse_content) end |