Class: ConvenientService::Examples::Dry::V1::Gemfile::Services::ParseContent
- Inherits:
-
Object
- Object
- ConvenientService::Examples::Dry::V1::Gemfile::Services::ParseContent
- Includes:
- DryService::Config
- Defined in:
- lib/convenient_service/examples/dry/v1/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
Methods included from Config
Instance Method Details
#parse_content ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/convenient_service/examples/dry/v1/gemfile/services/parse_content.rb', line 64 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
60 61 62 |
# File 'lib/convenient_service/examples/dry/v1/gemfile/services/parse_content.rb', line 60 def result success(data: {parsed_content: parse_content}) end |