Class: Coconductor::Vendorer

Inherits:
Object
  • Object
show all
Defined in:
lib/coconductor/vendorer.rb

Constant Summary collapse

OPTIONS =
%i[filename url repo replacements html source_path wiki].freeze
INVALID_CHARS =
["\u202D", "\u202C", "\u200E", "\u200F"].freeze
UPPERCASE_WORD_REGEX =
/(?:[A-Z]{3,}+ ?)+[A-Z_]+/.freeze
UNMARKED_FIELD_REGEX =
/(?<= |^)#{UPPERCASE_WORD_REGEX}(?= |\.|,)/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(family, options = {}) ⇒ Vendorer

Returns a new instance of Vendorer.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/coconductor/vendorer.rb', line 22

def initialize(family, options = {})
  @family = family

  OPTIONS.each do |option|
    instance_variable_set("@#{option}", options[option])
  end

  logger.info "Vendoring #{family}"

  mkdir
end

Instance Attribute Details

#familyObject (readonly)

Returns the value of attribute family.



14
15
16
# File 'lib/coconductor/vendorer.rb', line 14

def family
  @family
end

#raw_content=(value) ⇒ Object

Sets the attribute raw_content

Parameters:

  • value

    the value to set the attribute raw_content to.



15
16
17
# File 'lib/coconductor/vendorer.rb', line 15

def raw_content=(value)
  @raw_content = value
end

#refObject



58
59
60
# File 'lib/coconductor/vendorer.rb', line 58

def ref
  @ref ||= 'master'
end

#repoObject (readonly)

Returns the value of attribute repo.



14
15
16
# File 'lib/coconductor/vendorer.rb', line 14

def repo
  @repo
end

Instance Method Details

#contentObject



46
47
48
# File 'lib/coconductor/vendorer.rb', line 46

def content
  content_normalized
end

#dirObject



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

def dir
  @dir ||= File.expand_path family, vendor_dir
end

#filenameObject



38
39
40
# File 'lib/coconductor/vendorer.rb', line 38

def filename
  @filename ||= 'CODE_OF_CONDUCT.md'
end

#replacementsObject



62
63
64
# File 'lib/coconductor/vendorer.rb', line 62

def replacements
  @replacements ||= {}
end

#source_pathObject



42
43
44
# File 'lib/coconductor/vendorer.rb', line 42

def source_path
  @source_path ||= filename
end

#urlObject



50
51
52
# File 'lib/coconductor/vendorer.rb', line 50

def url
  @url || "https://github.com/#{repo}/raw/#{ref}/#{source_path}"
end

#vendor(version: '1.0') ⇒ Object



54
55
56
# File 'lib/coconductor/vendorer.rb', line 54

def vendor(version: '1.0')
  write_with_meta(content, version: version)
end

#write_with_meta(content, version: '1.0') ⇒ Object



66
67
68
69
# File 'lib/coconductor/vendorer.rb', line 66

def write_with_meta(content, version: '1.0')
  content = content_with_meta(content, 'version' => version)
  write(filepath(version), content)
end