kamaze-version 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +16 -0
- data/lib/kamaze-version.rb +24 -0
- data/lib/kamaze/version.rb +141 -0
- data/lib/kamaze/version/version.rb +13 -0
- data/lib/kamaze/version/version.yml +17 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ed38b410f00dcebd12e53ee1c45dea6614c4270028394a30635192c9d6dea3d
|
4
|
+
data.tar.gz: c178c9e7fc4d18b17f9e48f9d573a026ebfe41e2d9b0d544e7d5bf61dce09ae6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ec693c1c924eaae1c988beb69f210e7f25d94aae12838fd0046277edbab7c9190c4d733729f72b099035da310b7e1563ed787b31b132002d26ceee10fc7d320
|
7
|
+
data.tar.gz: a1e4401d485d5a92b6cc62a953840c14b9da2582c1953a60132638082d6fa54b4ffc4ba4f6401acb64d760332821ffb6a0cd35c1893524a22c846bc26eaad6c0
|
data/.yardopts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# vim: ft=sh
|
2
|
+
|
3
|
+
lib/**/*.rb \
|
4
|
+
--no-progress \
|
5
|
+
--markup-provider 'redcarpet' \
|
6
|
+
--markup 'markdown' \
|
7
|
+
--charset 'utf-8' \
|
8
|
+
--protected --private --embed-mixins \
|
9
|
+
--tag type:'type' --hide-tag 'type' \
|
10
|
+
--readme README.md \
|
11
|
+
--exclude '_flymake\\.rb$' \
|
12
|
+
--exclude '/\\.#'
|
13
|
+
|
14
|
+
# Local Variables:
|
15
|
+
# mode: sh
|
16
|
+
# End:
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift(__dir__)
|
10
|
+
|
11
|
+
lock = Dir.chdir("#{__dir__}/..") do
|
12
|
+
[['gems.rb', 'gems.locked'], ['Gemfile', 'Gemfile.lock']]
|
13
|
+
.map { |m| Dir.glob(m).size >= 2 }
|
14
|
+
.include?(true)
|
15
|
+
end
|
16
|
+
|
17
|
+
if lock
|
18
|
+
require 'rubygems'
|
19
|
+
require 'bundler/setup'
|
20
|
+
|
21
|
+
if Gem::Specification.find_all_by_name('kamaze-project').any?
|
22
|
+
require 'kamaze/project/core_ext/pp'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
autoload :Pathname, 'pathname'
|
10
|
+
autoload :Yaml, 'yaml'
|
11
|
+
require 'dry/inflector'
|
12
|
+
|
13
|
+
# rubocop:disable Style/Documentation
|
14
|
+
|
15
|
+
module Kamaze
|
16
|
+
class Version
|
17
|
+
autoload :VERSION, "#{__dir__}/version/version"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:enable Style/Documentation
|
22
|
+
|
23
|
+
# Describe version using a YAML file.
|
24
|
+
#
|
25
|
+
# @see https://github.com/jcangas/version_info
|
26
|
+
class Kamaze::Version
|
27
|
+
# Get filepath used to parse version (YAML file).
|
28
|
+
#
|
29
|
+
# @return [Pathname|String]
|
30
|
+
attr_reader :file
|
31
|
+
|
32
|
+
# @param [String|Pathname|nil] file
|
33
|
+
def initialize(file = nil)
|
34
|
+
(file.nil? ? file_from(caller_locations) : file).tap do |file|
|
35
|
+
@file = ::Pathname.new(file).freeze
|
36
|
+
end
|
37
|
+
parse!
|
38
|
+
end
|
39
|
+
|
40
|
+
# Denote version is semantically valid
|
41
|
+
#
|
42
|
+
# @return [Boolean]
|
43
|
+
def valid?
|
44
|
+
!!(/^([0-9]+\.){2}[0-9]+$/ =~ self.to_s)
|
45
|
+
rescue ::NameError
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
# @raise [NameError]
|
50
|
+
# @return [String]
|
51
|
+
def to_s
|
52
|
+
[major, minor, patch].map(&:to_i).join('.')
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Hash]
|
56
|
+
def to_h
|
57
|
+
parsed.clone.freeze
|
58
|
+
end
|
59
|
+
|
60
|
+
# Return the path as a String.
|
61
|
+
#
|
62
|
+
# @see https://ruby-doc.org/stdlib-2.5.0/libdoc/pathname/rdoc/Pathname.html#method-i-to_path
|
63
|
+
# @return [String]
|
64
|
+
def to_path
|
65
|
+
file.to_s
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
# Get parsed data
|
71
|
+
#
|
72
|
+
# @return [Hash]
|
73
|
+
attr_reader :parsed
|
74
|
+
|
75
|
+
# Get file automagically
|
76
|
+
#
|
77
|
+
# @param [Array] locations
|
78
|
+
# @return [Pathname]
|
79
|
+
def file_from(locations = caller_locations)
|
80
|
+
location = locations.first.path
|
81
|
+
|
82
|
+
Pathname.new(location).dirname.realpath.join('version.yml')
|
83
|
+
end
|
84
|
+
|
85
|
+
# Parse given file
|
86
|
+
#
|
87
|
+
# @param [Pathname] file
|
88
|
+
# @raise [Psych::DisallowedClass]
|
89
|
+
# @return [Hash]
|
90
|
+
def parse(file)
|
91
|
+
YAML.safe_load(file.read) || {}
|
92
|
+
rescue Errno::ENOENT
|
93
|
+
{}
|
94
|
+
end
|
95
|
+
|
96
|
+
# Parse and set attributes
|
97
|
+
#
|
98
|
+
# @return [self]
|
99
|
+
def parse!
|
100
|
+
@parsed = self.parse(self.file)
|
101
|
+
.map { |k, v| self.attr_set(k, v) }
|
102
|
+
.compact
|
103
|
+
.to_h
|
104
|
+
|
105
|
+
self
|
106
|
+
end
|
107
|
+
|
108
|
+
# Define attribute (as ``ro`` attr) and set value.
|
109
|
+
#
|
110
|
+
# @param [String|Symbol] attr_name
|
111
|
+
# @param [Object] attr_value
|
112
|
+
# @return [Array|nil]
|
113
|
+
def attr_set(attr_name, attr_value)
|
114
|
+
attr_name = Dry::Inflector.new.underscore(attr_name.to_s)
|
115
|
+
|
116
|
+
return nil unless eligible_attr?(attr_name)
|
117
|
+
|
118
|
+
self.singleton_class.class_eval do
|
119
|
+
attr_accessor attr_name
|
120
|
+
# rubocop:disable Style/AccessModifierDeclarations
|
121
|
+
protected "#{attr_name}="
|
122
|
+
# rubocop:enable Style/AccessModifierDeclarations
|
123
|
+
end
|
124
|
+
|
125
|
+
self.__send__("#{attr_name}=", attr_value.freeze)
|
126
|
+
|
127
|
+
[attr_name, attr_value.freeze].freeze
|
128
|
+
end
|
129
|
+
|
130
|
+
# Denote given attr name is eligible (to be set)
|
131
|
+
#
|
132
|
+
# @param [String|Symbol] attr_name
|
133
|
+
# @return [Boolean]
|
134
|
+
def eligible_attr?(attr_name)
|
135
|
+
[attr_name, "#{attr_name}="].each do |v|
|
136
|
+
return false if self.respond_to?(v, true)
|
137
|
+
end
|
138
|
+
|
139
|
+
true
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
4
|
+
# License GPLv3+: GNU GPL version 3 or later
|
5
|
+
# <http://www.gnu.org/licenses/gpl.html>.
|
6
|
+
# This is free software: you are free to change and redistribute it.
|
7
|
+
# There is NO WARRANTY, to the extent permitted by law.
|
8
|
+
|
9
|
+
require_relative '../version'
|
10
|
+
|
11
|
+
class Kamaze::Version
|
12
|
+
VERSION = self.new.freeze
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
major: 1
|
3
|
+
minor: 0
|
4
|
+
patch: 0
|
5
|
+
authors: ['Dimitri Arrigoni']
|
6
|
+
email: 'dimitri@arrigoni.me'
|
7
|
+
date: '2018-06-21'
|
8
|
+
summary: 'Provide version as an object'
|
9
|
+
description: 'Why use a simple String, when you can use an Object?'
|
10
|
+
homepage: 'https://github.com/SwagDevOps/kamaze-version'
|
11
|
+
licenses: ['GPL-3.0']
|
12
|
+
license_header: |
|
13
|
+
Copyright (C) 2017-2018 Dimitri Arrigoni <dimitri@arrigoni.me>
|
14
|
+
License GPLv3+: GNU GPL version 3 or later
|
15
|
+
<http://www.gnu.org/licenses/gpl.html>.
|
16
|
+
This is free software: you are free to change and redistribute it.
|
17
|
+
There is NO WARRANTY, to the extent permitted by law.
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kamaze-version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dimitri Arrigoni
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-inflector
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
description: Why use a simple String, when you can use an Object?
|
28
|
+
email: dimitri@arrigoni.me
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".yardopts"
|
34
|
+
- lib/kamaze-version.rb
|
35
|
+
- lib/kamaze/version.rb
|
36
|
+
- lib/kamaze/version/version.rb
|
37
|
+
- lib/kamaze/version/version.yml
|
38
|
+
homepage: https://github.com/SwagDevOps/kamaze-version
|
39
|
+
licenses:
|
40
|
+
- GPL-3.0
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.3.0
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.7.6
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Provide version as an object
|
62
|
+
test_files: []
|