Class: Afterlife::Release::ChangeVersion
- Inherits:
-
Object
- Object
- Afterlife::Release::ChangeVersion
- Defined in:
- lib/afterlife/release/change_version.rb
Constant Summary collapse
- RUBY_REGEXP =
/VERSION\s*=\s*['"]#{Bump::Semver::VERSION_REGEX}['"]/.freeze
- REGEXPS =
{ ruby: RUBY_REGEXP, gem: RUBY_REGEXP, node: /"version":\s*"#{Bump::Semver::VERSION_REGEX}"/, }.freeze
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#new_version ⇒ Object
readonly
Returns the value of attribute new_version.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #content ⇒ Object
- #current_version ⇒ Object
-
#initialize(new_version, options) ⇒ ChangeVersion
constructor
A new instance of ChangeVersion.
Constructor Details
#initialize(new_version, options) ⇒ ChangeVersion
Returns a new instance of ChangeVersion.
23 24 25 26 27 |
# File 'lib/afterlife/release/change_version.rb', line 23 def initialize(new_version, ) @file_path = [:real_path] @regexp = REGEXPS[[:type].to_sym] @new_version = new_version end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
21 22 23 |
# File 'lib/afterlife/release/change_version.rb', line 21 def file_path @file_path end |
#new_version ⇒ Object (readonly)
Returns the value of attribute new_version.
21 22 23 |
# File 'lib/afterlife/release/change_version.rb', line 21 def new_version @new_version end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
21 22 23 |
# File 'lib/afterlife/release/change_version.rb', line 21 def regexp @regexp end |
Class Method Details
.call(new_version) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/afterlife/release/change_version.rb', line 13 def self.call(new_version) Afterlife.current_repo.version_files.map do |file_def| instance = new(new_version, file_def) instance.call instance.file_path end end |
Instance Method Details
#call ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/afterlife/release/change_version.rb', line 29 def call fail "could not find a version for #{file_path}" unless current_version File.write( file_path, content.sub(current_version, new_version), ) end |
#content ⇒ Object
43 44 45 |
# File 'lib/afterlife/release/change_version.rb', line 43 def content @content ||= File.read(file_path) end |
#current_version ⇒ Object
38 39 40 41 |
# File 'lib/afterlife/release/change_version.rb', line 38 def current_version content[regexp] Regexp.last_match(1) end |