Class: Canpe::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/canpe/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, store) ⇒ Repository

Returns a new instance of Repository.



12
13
14
15
# File 'lib/canpe/repository.rb', line 12

def initialize(name, store)
  @name = name
  @store = store
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/canpe/repository.rb', line 10

def name
  @name
end

#storeObject (readonly)

Returns the value of attribute store.



10
11
12
# File 'lib/canpe/repository.rb', line 10

def store
  @store
end

Instance Method Details

#binding_option_urlObject



27
28
29
# File 'lib/canpe/repository.rb', line 27

def binding_option_url
  File.join(repository_url, 'binding.yml')
end

#binding_optionsObject



31
32
33
# File 'lib/canpe/repository.rb', line 31

def binding_options
  @_binding_options ||= File.exists?(binding_option_url) ? YAML.load_file(binding_option_url) : {}
end

#file_paths(absolute_path: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/canpe/repository.rb', line 35

def file_paths(absolute_path: false)
  files = Dir.glob(File.join(templates_url, '**', '*'), File::FNM_DOTMATCH)
  files = files.reject { |e| [".", ".."].any? { |s| s== File::basename(e) } }

  if absolute_path
    files.map { |file| Pathname.new(file) }
  else
    base = Pathname.new(templates_url)
    files.map { |file| Pathname.new(file).relative_path_from(base) }
  end
end

#match?(query) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/canpe/repository.rb', line 51

def match?(query)
  /#{query}/ === to_s
end

#repository_urlObject

Directory which is root directory of this repository



18
19
20
# File 'lib/canpe/repository.rb', line 18

def repository_url
  File.join(store.repositories_root, name)
end

#templates_urlObject

Directory in which templates file exists



23
24
25
# File 'lib/canpe/repository.rb', line 23

def templates_url
  File.join(store.repositories_root, name, 'templates')
end

#to_sObject



47
48
49
# File 'lib/canpe/repository.rb', line 47

def to_s
  "#{store.name}::#{name}"
end