eac_tools 0.48.1 → 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +21 -21
  3. data/lib/eac_tools/version.rb +1 -1
  4. data/sub/avm/avm.gemspec +2 -2
  5. data/sub/avm/lib/avm/registry/sources.rb +21 -0
  6. data/sub/avm/lib/avm/scms/auto_commit/file_resource_name/ruby.rb +23 -0
  7. data/sub/avm/lib/avm/scms/auto_commit/file_resource_name.rb +31 -0
  8. data/sub/avm/lib/avm/scms/auto_commit/for_file.rb +72 -0
  9. data/sub/{avm-git/lib/avm/git → avm/lib/avm/scms}/auto_commit/rules/base.rb +3 -2
  10. data/sub/{avm-git/lib/avm/git → avm/lib/avm/scms}/auto_commit/rules/last.rb +4 -4
  11. data/sub/{avm-git/lib/avm/git → avm/lib/avm/scms}/auto_commit/rules/manual.rb +5 -10
  12. data/sub/avm/lib/avm/scms/auto_commit/rules/new.rb +24 -0
  13. data/sub/{avm-git/lib/avm/git → avm/lib/avm/scms}/auto_commit/rules/nth.rb +4 -4
  14. data/sub/{avm-git/lib/avm/git → avm/lib/avm/scms}/auto_commit/rules/unique.rb +4 -4
  15. data/sub/{avm-git/lib/avm/git → avm/lib/avm/scms}/auto_commit/rules.rb +7 -2
  16. data/sub/avm/lib/avm/scms/auto_commit.rb +11 -0
  17. data/sub/avm/lib/avm/scms/base/commits.rb +27 -0
  18. data/sub/avm/lib/avm/scms/base/milestones.rb +21 -0
  19. data/sub/avm/lib/avm/scms/base.rb +8 -2
  20. data/sub/avm/lib/avm/scms/changed_file.rb +26 -0
  21. data/sub/avm/lib/avm/scms/commit.rb +15 -0
  22. data/sub/avm/lib/avm/scms/commit_info.rb +20 -0
  23. data/sub/avm/lib/avm/scms/interval.rb +18 -0
  24. data/sub/avm/lib/avm/scms.rb +9 -0
  25. data/sub/avm/lib/avm/sources/base/stereotype.rb +18 -0
  26. data/sub/avm/lib/avm/version.rb +1 -1
  27. data/sub/{avm-git/spec/lib/avm/git/auto_commit_path_spec.rb → avm/spec/lib/avm/scms/auto_commit/file_resource_name_spec.rb} +2 -2
  28. data/sub/avm-git/avm-git.gemspec +3 -3
  29. data/sub/avm-git/lib/avm/git/scms/git/changed_file.rb +16 -0
  30. data/sub/avm-git/lib/avm/git/scms/git/changed_files.rb +24 -0
  31. data/sub/avm-git/lib/avm/git/scms/git/commit.rb +10 -0
  32. data/sub/avm-git/lib/avm/git/scms/git/commits.rb +57 -0
  33. data/sub/avm-git/lib/avm/git/scms/git/interval.rb +31 -0
  34. data/sub/avm-git/lib/avm/git/scms/git/milestones.rb +21 -0
  35. data/sub/avm-git/lib/avm/git/scms/git/run_commit.rb +57 -0
  36. data/sub/avm-git/lib/avm/git/scms/git.rb +6 -35
  37. data/sub/avm-git/lib/avm/git/scms/git_subrepo.rb +2 -1
  38. data/sub/avm-git/lib/avm/git/version.rb +1 -1
  39. data/sub/avm-tools/avm-tools.gemspec +2 -2
  40. data/sub/avm-tools/lib/avm/tools/runner/git/subrepo/fix.rb +12 -4
  41. data/sub/avm-tools/lib/avm/tools/runner/{git → source}/auto_commit.rb +12 -9
  42. data/sub/avm-tools/lib/avm/tools/version.rb +1 -1
  43. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/{value.rb → item.rb} +7 -13
  44. data/sub/eac_ruby_utils/lib/eac_ruby_utils/listable/list.rb +14 -4
  45. data/sub/eac_ruby_utils/lib/eac_ruby_utils/patches/pathname/assert_parent.rb +12 -0
  46. data/sub/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
  47. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/listable_spec.rb +10 -10
  48. data/sub/eac_ruby_utils/spec/lib/eac_ruby_utils/patches/pathname/assert_parent_spec.rb +21 -0
  49. metadata +39 -30
  50. data/sub/avm-git/lib/avm/git/auto_commit/commit_info.rb +0 -23
  51. data/sub/avm-git/lib/avm/git/auto_commit/rules/new.rb +0 -24
  52. data/sub/avm-git/lib/avm/git/auto_commit_path/ruby.rb +0 -20
  53. data/sub/avm-git/lib/avm/git/auto_commit_path.rb +0 -28
  54. data/sub/avm-git/lib/avm/git/file_auto_fixup.rb +0 -83
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
5
+ module Avm
6
+ module Sources
7
+ class Base
8
+ module Stereotype
9
+ STEREOTYPE_NAME_KEY = 'stereotype'
10
+
11
+ # @return [String, nil]
12
+ def stereotype_name_by_configuration
13
+ configuration.entry(STEREOTYPE_NAME_KEY).value
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Avm
4
- VERSION = '0.57.0'
4
+ VERSION = '0.59.0'
5
5
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'avm/git/auto_commit_path'
3
+ require 'avm/scms/auto_commit/file_resource_name'
4
4
 
5
- RSpec.describe ::Avm::Git::AutoCommitPath, git: true do
5
+ RSpec.describe ::Avm::Scms::AutoCommit::FileResourceName, git: true do
6
6
  let(:git) { stubbed_git_local_repo }
7
7
 
8
8
  describe '#class_name' do
@@ -12,11 +12,11 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.files = Dir['{lib}/**/*']
14
14
 
15
- s.add_dependency 'avm', '~> 0.57'
15
+ s.add_dependency 'avm', '~> 0.59'
16
16
  s.add_dependency 'avm-files', '~> 0.6'
17
17
  s.add_dependency 'eac_git', '~> 0.14'
18
- s.add_dependency 'eac_ruby_utils', '~> 0.108'
19
- s.add_dependency 'git', '~> 1.12'
18
+ s.add_dependency 'eac_ruby_utils', '~> 0.110', '>= 0.110.1'
19
+ s.add_dependency 'git', '~> 1.13'
20
20
 
21
21
  s.add_development_dependency 'aranha-parsers', '~> 0.8', '>= 0.8.5'
22
22
  s.add_development_dependency 'eac_ruby_gem_support', '~> 0.4'
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/changed_file'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class Git < ::Avm::Scms::Base
10
+ class ChangedFile < ::Avm::Scms::ChangedFile
11
+ common_constructor :scm, :path
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/git/scms/git/changed_file'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class Git < ::Avm::Scms::Base
10
+ class ChangedFiles
11
+ enable_method_class
12
+ common_constructor :scm
13
+
14
+ # @return [Avm::Git::Scms::Git::ChangedFile]
15
+ def result
16
+ scm.git_repo.dirty_files.map do |dirty_file|
17
+ ::Avm::Git::Scms::Git::ChangedFile.new(scm, dirty_file.path)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -15,11 +15,18 @@ module Avm
15
15
  delegate :git_repo, to: :git_scm
16
16
  delegate :id, to: :git_commit
17
17
 
18
+ FIXUP_SUBJECT_PATTERN = /\Afixup\!/.freeze
19
+
18
20
  # @return [Array<Pathname>]
19
21
  def changed_files
20
22
  git_commit.changed_files.map { |cf| cf.path.to_pathname }
21
23
  end
22
24
 
25
+ # @return [Boolean]
26
+ def fixup?
27
+ FIXUP_SUBJECT_PATTERN.match?(git_commit.subject)
28
+ end
29
+
23
30
  # @param other [Avm::Git::Scms::Git::Commit]
24
31
  # @return [Avm::Git::Scms::Git::Commit]
25
32
  def merge_with(other)
@@ -43,6 +50,9 @@ module Avm
43
50
  %w[.gitrepo .gitmodules].any? { |file| file.include?(path.basename.to_path) }
44
51
  end
45
52
 
53
+ # @return [String]
54
+ delegate :subject, to: :git_commit
55
+
46
56
  private
47
57
 
48
58
  def validate_clean_and_head
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/commit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class Git < ::Avm::Scms::Base
10
+ module Commits
11
+ # @return [Avm::Git::Scms::Git::Commit,nil]
12
+ def commit(source)
13
+ if source.is_a?(::Avm::Git::Scms::Git::Commit)
14
+ return source if source.git_repo == git_repo
15
+
16
+ raise 'Not same Git repository'
17
+ end
18
+ git_repo.commitize(source).if_present do |v|
19
+ ::Avm::Git::Scms::Git::Commit.new(self, v)
20
+ end
21
+ end
22
+
23
+ # @return [Avm::Git::Scms::Git::Commit,nil]
24
+ def commit_dirty(message = nil)
25
+ return nil unless git_repo.dirty?
26
+
27
+ git_repo.command('add', '.').execute!
28
+ git_repo.command(
29
+ 'commit', '-m',
30
+ message.call_if_proc.if_present(COMMIT_DIRTY_DEFAULT_MESSAGE)
31
+ ).execute!
32
+ head_commit
33
+ end
34
+
35
+ # @return [Avm::Git::Scms::Git::Commit,nil]
36
+ def commit_if_change(message = nil)
37
+ tracker = ::Avm::Git::Scms::Git::ChangeTracker.new(self, message)
38
+ tracker.start
39
+ yield
40
+ tracker.stop
41
+ end
42
+
43
+ # @return [Avm::Git::Scms::Git::Commit]
44
+ def head_commit
45
+ commit(git_repo.head)
46
+ end
47
+
48
+ # @return [Avm::Git::Scms::Git::Commit]
49
+ def reset_and_commit(commit_to_reset, message)
50
+ git_repo.command('reset', '--soft', commit(commit_to_reset).git_commit.id).execute!
51
+ commit_dirty(message)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/interval'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class Git < ::Avm::Scms::Base
10
+ class Interval < ::Avm::Scms::Interval
11
+ def initialize(scm, from, to)
12
+ super(scm, from, to)
13
+ self.from = scm.commit(from)
14
+ self.to = scm.commit(to)
15
+ end
16
+
17
+ # @return [Array<Avm::Git::Scms::Git::Commit>]
18
+ def commits
19
+ scm.git_repo.command('log', '--pretty=format:%H', git_commit_interval).execute!
20
+ .each_line.map { |sha1| scm.commit(sha1.strip) }
21
+ end
22
+
23
+ # @return [String]
24
+ def git_commit_interval
25
+ [from.id, to.id].join('..')
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/commit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class Git < ::Avm::Scms::Base
10
+ module Milestones
11
+ BASE_COMMIT_REFERENCE = 'origin/master'
12
+
13
+ # @return [Avm::Git::Scms::Git::Commit]
14
+ def current_milestone_base_commit
15
+ commit(BASE_COMMIT_REFERENCE)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'avm/scms/commit'
4
+ require 'eac_ruby_utils/core_ext'
5
+
6
+ module Avm
7
+ module Git
8
+ module Scms
9
+ class Git < ::Avm::Scms::Base
10
+ class RunCommit
11
+ enable_method_class
12
+
13
+ common_constructor :scm, :commit_info
14
+
15
+ # @return [Avm::Git::Scms::Git::Commit]
16
+ def result
17
+ reset
18
+ add_paths
19
+ commit
20
+
21
+ scm.head_commit
22
+ end
23
+
24
+ protected
25
+
26
+ def add_path(path)
27
+ scm.git_repo.command(
28
+ *(path.exist? ? ['add'] : ['rm', '-f']),
29
+ path.relative_path_from(scm.path)
30
+ ).execute!
31
+ end
32
+
33
+ def add_paths
34
+ commit_info.paths.each { |path| add_path(path) }
35
+ end
36
+
37
+ def commit
38
+ scm.git_repo.command('commit', *commit_args).execute!
39
+ end
40
+
41
+ # @return [Array<String>]
42
+ def commit_args
43
+ r = commit_info.fixup.if_present([]) { |v| ['--fixup', v.id] }
44
+ r += commit_info.message.if_present([]) { |v| ['--message', v] }
45
+ return r if r.any?
46
+
47
+ raise 'Argument list is empty'
48
+ end
49
+
50
+ def reset
51
+ scm.git_repo.command('reset', '--soft', 'HEAD').execute!
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -8,7 +8,7 @@ module Avm
8
8
  module Git
9
9
  module Scms
10
10
  class Git < ::Avm::Scms::Base
11
- require_sub __FILE__
11
+ require_sub __FILE__, include_modules: true
12
12
  include ::Comparable
13
13
 
14
14
  COMMIT_DIRTY_DEFAULT_MESSAGE = 'Dirty files.'
@@ -17,44 +17,15 @@ module Avm
17
17
  git_repo <=> other.git_repo
18
18
  end
19
19
 
20
- # @return [Avm::Git::Scms::Git::Commit,nil]
21
- def commit(source)
22
- if source.is_a?(::Avm::Git::Scms::Git::Commit)
23
- return source if source.git_repo == self
24
-
25
- raise 'Not same Git repository'
26
- end
27
- git_repo.commitize(source).if_present do |v|
28
- ::Avm::Git::Scms::Git::Commit.new(self, v)
29
- end
30
- end
31
-
32
- # @return [Avm::Git::Scms::Git::Commit,nil]
33
- def commit_dirty(message = nil)
34
- return nil unless git_repo.dirty?
35
-
36
- git_repo.command('add', '.').execute!
37
- git_repo.command('commit', '-m',
38
- message.call_if_proc.if_present(COMMIT_DIRTY_DEFAULT_MESSAGE)).execute!
39
- commit(git_repo.head)
40
- end
41
-
42
- # @return [Avm::Git::Scms::Git::Commit,nil]
43
- def commit_if_change(message = nil)
44
- tracker = ::Avm::Git::Scms::Git::ChangeTracker.new(self, message)
45
- tracker.start
46
- yield
47
- tracker.stop
48
- end
49
-
50
20
  def git_repo
51
21
  @git_repo ||= ::EacGit::Local.new(path)
52
22
  end
53
23
 
54
- # @return [Avm::Git::Scms::Git::Commit]
55
- def reset_and_commit(commit_to_reset, message)
56
- git_repo.command('reset', '--soft', commit(commit_to_reset).git_commit.id).execute!
57
- commit_dirty(message)
24
+ # @param from [Avm::Git::Scms::Git::Commit]
25
+ # @param to [Avm::Git::Scms::Git::Commit]
26
+ # @return [Avm::Git::Scms::Git::Interval]
27
+ def interval(from, to)
28
+ ::Avm::Git::Scms::Git::Interval.new(self, from, to)
58
29
  end
59
30
 
60
31
  # @return [Enumerable<Avm::Git::Scms::GitSubrepo>]
@@ -8,7 +8,8 @@ module Avm
8
8
  module Git
9
9
  module Scms
10
10
  class GitSubrepo < ::Avm::Scms::Base
11
- delegate :commit_if_change, to: :parent_scm
11
+ delegate :changed_files, :commit_if_change, :current_milestone_base_commit, :interval,
12
+ :head_commit, :run_commit, to: :parent_scm
12
13
 
13
14
  def update
14
15
  git_subrepo.command('clean').execute!
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Git
5
- VERSION = '0.10.1'
5
+ VERSION = '0.11.0'
6
6
  end
7
7
  end
@@ -15,11 +15,11 @@ Gem::Specification.new do |s|
15
15
  s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
16
 
17
17
  s.add_dependency 'aranha-parsers', '~> 0.14', '>= 0.14.4'
18
- s.add_dependency 'avm', '~> 0.57'
18
+ s.add_dependency 'avm', '~> 0.59'
19
19
  s.add_dependency 'avm-eac_ruby_base1', '~> 0.27', '>= 0.27.3'
20
20
  s.add_dependency 'avm-eac_ubuntu_base0', '~> 0.4'
21
21
  s.add_dependency 'avm-files', '~> 0.6'
22
- s.add_dependency 'avm-git', '~> 0.10', '>= 0.10.1'
22
+ s.add_dependency 'avm-git', '~> 0.11'
23
23
  s.add_dependency 'clipboard', '~> 1.3', '>= 1.3.6'
24
24
  s.add_dependency 'curb', '~> 0.9', '>= 0.9.11'
25
25
  s.add_dependency 'eac_git', '~> 0.14'
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'avm/tools/core_ext'
4
- require 'avm/git/auto_commit/rules/unique'
5
- require 'avm/git/file_auto_fixup'
4
+ require 'avm/git/scms/git'
6
5
  require 'avm/git/subrepo_checks'
6
+ require 'avm/scms/auto_commit/rules/unique'
7
+ require 'avm/scms/auto_commit/for_file'
7
8
  require 'eac_git/local'
8
9
 
9
10
  module Avm
@@ -31,8 +32,10 @@ module Avm
31
32
  infov 'Dirty files', local_repos.dirty_files.count
32
33
  local_repos.dirty_files.each do |file|
33
34
  infov ' * Ammending', file.path
34
- ::Avm::Git::FileAutoFixup.new(runner_context.call(:git), file.path,
35
- [::Avm::Git::AutoCommit::Rules::Unique.new]).run
35
+ ::Avm::Scms::AutoCommit::ForFile.new(
36
+ git_scm, file.path,
37
+ [::Avm::Scms::AutoCommit::Rules::Unique.new]
38
+ ).run
36
39
  end
37
40
  end
38
41
 
@@ -43,6 +46,11 @@ module Avm
43
46
  !c.result.error?
44
47
  end
45
48
 
49
+ # @return [Avm::Git::Scms::Git]
50
+ def git_scm_uncached
51
+ ::Avm::Git::Scms::Git.new(runner_context.call(:git).root_path)
52
+ end
53
+
46
54
  def new_check(fix_parent = false)
47
55
  r = ::Avm::Git::SubrepoChecks.new(local_repos).add_all_subrepos
48
56
  r.fix_parent = fix_parent
@@ -2,13 +2,13 @@
2
2
 
3
3
  require 'eac_cli/core_ext'
4
4
  require 'avm/file_formats/search_formatter'
5
- require 'avm/git/file_auto_fixup'
6
- require 'avm/git/auto_commit/rules'
5
+ require 'avm/scms/auto_commit/for_file'
6
+ require 'avm/scms/auto_commit/rules'
7
7
 
8
8
  module Avm
9
9
  module Tools
10
10
  class Runner
11
- class Git
11
+ class Source < ::Avm::Sources::Runner
12
12
  class AutoCommit
13
13
  runner_with :help do
14
14
  desc 'Auto fixup files.'
@@ -19,13 +19,18 @@ module Avm
19
19
  end
20
20
 
21
21
  def run
22
- runner_context.call(:git).command('reset', 'HEAD').system!
23
22
  format_files
24
23
  files.each do |file|
25
- ::Avm::Git::FileAutoFixup.new(runner_context.call(:git), file, rules).run
24
+ ::Avm::Scms::AutoCommit::ForFile.new(runner_context.call(:source).scm, file, rules)
25
+ .run
26
26
  end
27
27
  end
28
28
 
29
+ def help_extra_text
30
+ "Rules\n" + ::Avm::Scms::AutoCommit::Rules.all
31
+ .map { |r| ' ' + r.keys.join(', ') + "\n" }.join
32
+ end
33
+
29
34
  private
30
35
 
31
36
  def files_uncached
@@ -48,14 +53,12 @@ module Avm
48
53
  def dirty_files
49
54
  return [] unless parsed.dirty?
50
55
 
51
- runner_context.call(:git).dirty_files.map do |file|
52
- file.path.to_pathname.expand_path(runner_context.call(:git).root_path)
53
- end
56
+ runner_context.call(:source).scm.changed_files.map(&:absolute_path)
54
57
  end
55
58
 
56
59
  def rules
57
60
  parsed.rule.map do |rule_string|
58
- ::Avm::Git::AutoCommit::Rules.parse(rule_string)
61
+ ::Avm::Scms::AutoCommit::Rules.parse(rule_string)
59
62
  end
60
63
  end
61
64
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Avm
4
4
  module Tools
5
- VERSION = '0.142.8'
5
+ VERSION = '0.143.0'
6
6
  end
7
7
  end
@@ -1,25 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'eac_ruby_utils/patches/class/common_constructor'
3
4
  require 'eac_ruby_utils/inflector'
4
5
 
5
6
  module EacRubyUtils
6
7
  module Listable
7
- class Value
8
- attr_reader :value, :key
9
-
10
- def initialize(list, value, key, translation_required = true)
11
- @list = list
12
- @value = value
13
- @key = key
14
- @translation_required = translation_required
15
- end
8
+ class Item
9
+ common_constructor :list, :value, :key, :translation_required, default: [true]
16
10
 
17
11
  def to_s
18
- "I: #{@list.item}, V: #{@value}, K: #{@key}"
12
+ "I: #{list.item}, V: #{value}, K: #{key}"
19
13
  end
20
14
 
21
15
  def constant_name
22
- ::EacRubyUtils::Inflector.variableize("#{@list.item}_#{@key}").upcase
16
+ ::EacRubyUtils::Inflector.variableize("#{list.item}_#{key}").upcase
23
17
  end
24
18
 
25
19
  def label
@@ -36,13 +30,13 @@ module EacRubyUtils
36
30
  end
37
31
 
38
32
  def translation_required?
39
- @translation_required
33
+ translation_required
40
34
  end
41
35
 
42
36
  private
43
37
 
44
38
  def translate(translate_key)
45
- full_translate_key = "#{@list.i18n_key}.#{@key}.#{translate_key}"
39
+ full_translate_key = "#{list.i18n_key}.#{key}.#{translate_key}"
46
40
  if !::I18n.exists?(full_translate_key) && !translation_required?
47
41
  ''
48
42
  else
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'eac_ruby_utils/listable/value'
3
+ require 'eac_ruby_utils/listable/item'
4
4
 
5
5
  module EacRubyUtils
6
6
  module Listable
@@ -18,13 +18,23 @@ module EacRubyUtils
18
18
  end
19
19
 
20
20
  def blank_value
21
- @blank_value ||= ::EacRubyUtils::Listable::Value.new(self, BLANK_VALUE, BLANK_KEY, false)
21
+ @blank_value ||= ::EacRubyUtils::Listable::Item.new(self, BLANK_VALUE, BLANK_KEY, false)
22
22
  end
23
23
 
24
24
  def each_value(&block)
25
25
  values.each(&block)
26
26
  end
27
27
 
28
+ # @return [EacRubyUtils::Listable::Item, nil]
29
+ def item_by_value(value)
30
+ @values.values.find { |item| item.value == value }
31
+ end
32
+
33
+ # @return [EacRubyUtils::Listable::Item]
34
+ def item_by_value!(value)
35
+ item_by_value(value) || raise(::KeyError, "Value not found: #{value}")
36
+ end
37
+
28
38
  def values
29
39
  @values.values.map(&:value)
30
40
  end
@@ -59,7 +69,7 @@ module EacRubyUtils
59
69
  "eac_ruby_utils.listable.#{class_i18n_key}.#{item}"
60
70
  end
61
71
 
62
- # @return [EacRubyUtils::Listable::Value, nil]
72
+ # @return [EacRubyUtils::Listable::Item, nil]
63
73
  def instance_value(instance)
64
74
  v = instance.send(item)
65
75
  return blank_value if v.blank?
@@ -109,7 +119,7 @@ module EacRubyUtils
109
119
  def build_values(labels)
110
120
  vs = {}
111
121
  parse_labels(labels).each do |value, key|
112
- v = Value.new(self, value, key)
122
+ v = ::EacRubyUtils::Listable::Item.new(self, value, key)
113
123
  vs[v.value] = v
114
124
  end
115
125
  vs
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ class Pathname
6
+ # Invoke +mkpath+ for parent path and return +self+.
7
+ # @return [self]
8
+ def assert_parent
9
+ parent.mkpath
10
+ self
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.109.1'
4
+ VERSION = '0.110.1'
5
5
  end
@@ -87,52 +87,52 @@ RSpec.describe ::EacRubyUtils::Listable do
87
87
  it { expect(stub_class.lists.is_a?(::EacRubyUtils::Listable::Lists)).to eq(true) }
88
88
 
89
89
  it {
90
- expect(stub_class.lists.inteiro.value_a.is_a?(::EacRubyUtils::Listable::Value))
90
+ expect(stub_class.lists.inteiro.value_a.is_a?(::EacRubyUtils::Listable::Item))
91
91
  .to eq(true)
92
92
  }
93
93
 
94
94
  it {
95
- expect(stub_class.lists.inteiro.value_b.is_a?(::EacRubyUtils::Listable::Value))
95
+ expect(stub_class.lists.inteiro.value_b.is_a?(::EacRubyUtils::Listable::Item))
96
96
  .to eq(true)
97
97
  }
98
98
 
99
99
  it {
100
- expect(stub_class.lists.inteiro.value_c.is_a?(::EacRubyUtils::Listable::Value))
100
+ expect(stub_class.lists.inteiro.value_c.is_a?(::EacRubyUtils::Listable::Item))
101
101
  .to eq(true)
102
102
  }
103
103
 
104
104
  it {
105
- expect(stub_class.lists.code.value_a.is_a?(::EacRubyUtils::Listable::Value))
105
+ expect(stub_class.lists.code.value_a.is_a?(::EacRubyUtils::Listable::Item))
106
106
  .to eq(true)
107
107
  }
108
108
 
109
109
  it {
110
- expect(stub_class.lists.code.value_b.is_a?(::EacRubyUtils::Listable::Value))
110
+ expect(stub_class.lists.code.value_b.is_a?(::EacRubyUtils::Listable::Item))
111
111
  .to eq(true)
112
112
  }
113
113
 
114
114
  it {
115
- expect(stub_class.lists.cadeia.value_a.is_a?(::EacRubyUtils::Listable::Value))
115
+ expect(stub_class.lists.cadeia.value_a.is_a?(::EacRubyUtils::Listable::Item))
116
116
  .to eq(true)
117
117
  }
118
118
 
119
119
  it {
120
- expect(stub_class.lists.cadeia.value_b.is_a?(::EacRubyUtils::Listable::Value))
120
+ expect(stub_class.lists.cadeia.value_b.is_a?(::EacRubyUtils::Listable::Item))
121
121
  .to eq(true)
122
122
  }
123
123
 
124
124
  it {
125
- expect(stub_class.lists.cadeia.value_c.is_a?(::EacRubyUtils::Listable::Value))
125
+ expect(stub_class.lists.cadeia.value_c.is_a?(::EacRubyUtils::Listable::Item))
126
126
  .to eq(true)
127
127
  }
128
128
 
129
129
  it {
130
- expect(stub_class.lists.type.value_a.is_a?(::EacRubyUtils::Listable::Value))
130
+ expect(stub_class.lists.type.value_a.is_a?(::EacRubyUtils::Listable::Item))
131
131
  .to eq(true)
132
132
  }
133
133
 
134
134
  it {
135
- expect(stub_class.lists.type.value_b.is_a?(::EacRubyUtils::Listable::Value))
135
+ expect(stub_class.lists.type.value_b.is_a?(::EacRubyUtils::Listable::Item))
136
136
  .to eq(true)
137
137
  }
138
138
  end