Module: VersionInfo

Defined in:
lib/version_info.rb,
lib/version_info/data.rb,
lib/version_info/storage.rb,
lib/version_info/version.rb,
lib/version_info/rake_tasks.rb,
lib/version_info/thor_tasks.rb,
lib/version_info/text_storage.rb,
lib/version_info/yaml_storage.rb,
lib/version_info/module_storage.rb

Defined Under Namespace

Modules: ThorTasks Classes: Data, ModuleStorage, RakeTasks, Storage, TextStorage, YamlStorage

Constant Summary collapse

STORAGE_CLASS =
{text: TextStorage, yaml: YamlStorage, module: ModuleStorage}
VERSION =
"1.9.0"

Class Method Summary collapse

Class Method Details

.file_formatObject



16
17
18
# File 'lib/version_info.rb', line 16

def self.file_format
  @file_format ||= :module
end

.file_format=(value) ⇒ Object



20
21
22
# File 'lib/version_info.rb', line 20

def self.file_format=(value)
  @file_format = value
end

.included(other) ⇒ Object



34
35
36
# File 'lib/version_info.rb', line 34

def self.included(other)
  self.versionable(other)
end

.install_tasks(options) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/version_info.rb', line 24

def self.install_tasks(options)
  if defined?(Rake)
    require 'version_info/rake_tasks' 
    RakeTasks.install(options) 
  elsif defined?(Thor)
    require 'version_info/thor_tasks'
    ThorTasks.install(options)
  end
end

.segmentsObject

current segments or defaults



7
8
9
# File 'lib/version_info.rb', line 7

def self.segments
  @segments ||= [:major, :minor, :patch] 
end

.segments=(values) ⇒ Object

define segments



12
13
14
# File 'lib/version_info.rb', line 12

def self.segments=(values)
  @segments = values
end

.versionable(other) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/version_info.rb', line 38

def self.versionable(other)
  if other.const_defined?(:VERSION, false)
    old_const = other.const_get(:VERSION, false) 
    other.send(:remove_const, :VERSION) rescue true
  end
  other.const_set(:VERSION, Data.new(VersionInfo.segments.dup))
  singleton = other.singleton_class
  singleton.class_eval do
    define_method :VERSION do
      @data ||= self::VERSION
    end    
    define_method :"VERSION=" do |value_str|
      self.VERSION.set_version_info(value_str)
    end    
  end
  other.VERSION= old_const.to_s if old_const
end