Module: SdocAll::Base::ClassMethods
- Included in:
- SdocAll::Base
- Defined in:
- lib/sdoc_all/base.rb
Constant Summary collapse
- BASE_PATH =
Pathname.new(Dir.pwd).
- DOCS_PATH =
BASE_PATH + 'docs'
- PUBLIC_PATH =
BASE_PATH + 'public'
Instance Method Summary collapse
- #add_merge_task(options = {}) ⇒ Object
- #add_task(options = {}) ⇒ Object
- #base_path ⇒ Object
- #clear ⇒ Object
- #docs_path ⇒ Object
- #entries ⇒ Object
- #inherited(subclass) ⇒ Object
- #public_path ⇒ Object
- #remove_if_present(path) ⇒ Object
- #short_name ⇒ Object
- #sources_path ⇒ Object
- #subclasses ⇒ Object
- #system(*args) ⇒ Object
- #tasks(options = {}) ⇒ Object
- #to_document(type, config) ⇒ Object
- #used_sources ⇒ Object
- #with_env(key, value) ⇒ Object
Instance Method Details
#add_merge_task(options = {}) ⇒ Object
113 114 115 |
# File 'lib/sdoc_all/base.rb', line 113 def add_merge_task( = {}) @@tasks << MergeTask.new() end |
#add_task(options = {}) ⇒ Object
109 110 111 |
# File 'lib/sdoc_all/base.rb', line 109 def add_task( = {}) @@tasks << Task.new() end |
#base_path ⇒ Object
36 37 38 |
# File 'lib/sdoc_all/base.rb', line 36 def base_path BASE_PATH end |
#clear ⇒ Object
74 75 76 |
# File 'lib/sdoc_all/base.rb', line 74 def clear entries.clear end |
#docs_path ⇒ Object
40 41 42 |
# File 'lib/sdoc_all/base.rb', line 40 def docs_path DOCS_PATH.tap(&:mkpath) end |
#entries ⇒ Object
70 71 72 |
# File 'lib/sdoc_all/base.rb', line 70 def entries @entries ||= [] end |
#inherited(subclass) ⇒ Object
66 67 68 |
# File 'lib/sdoc_all/base.rb', line 66 def inherited(subclass) subclasses[subclass.short_name] = subclass end |
#public_path ⇒ Object
44 45 46 |
# File 'lib/sdoc_all/base.rb', line 44 def public_path PUBLIC_PATH end |
#remove_if_present(path) ⇒ Object
124 125 126 |
# File 'lib/sdoc_all/base.rb', line 124 def remove_if_present(path) FileUtils.remove_entry(path) if File.exist?(path) end |
#short_name ⇒ Object
52 53 54 |
# File 'lib/sdoc_all/base.rb', line 52 def short_name name.demodulize.underscore end |
#sources_path ⇒ Object
56 57 58 59 60 |
# File 'lib/sdoc_all/base.rb', line 56 def sources_path Pathname.new("sources/#{short_name}").tap do |path| path.mkpath end end |
#subclasses ⇒ Object
48 49 50 |
# File 'lib/sdoc_all/base.rb', line 48 def subclasses @subclasses ||= {} end |
#system(*args) ⇒ Object
117 118 119 120 121 122 |
# File 'lib/sdoc_all/base.rb', line 117 def system(*args) escaped_args = args.map(&:to_s).map{ |arg| arg[/[^a-z0-9\/\-.]/i] ? arg.inspect : arg } command = escaped_args.join(' ') puts "Executing #{command.length > 250 ? "#{command[0, 247]}..." : command}" Kernel.system(*args) end |
#tasks(options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sdoc_all/base.rb', line 89 def tasks( = {}) @@tasks = [] entries.each do |entry| entry.add_tasks() end subclasses.values.each do |subclass| unless subclass.used_sources.empty? paths = FileList.new paths.include(subclass.sources_path + '*') subclass.used_sources.each do |path| paths.exclude(path) end paths.resolve.each do |path| remove_if_present(path) end end end @@tasks end |
#to_document(type, config) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/sdoc_all/base.rb', line 78 def to_document(type, config) type = type.to_s config.symbolize_keys! if config.is_a?(Hash) subclass = subclasses[type] || subclasses[type.singularize] || subclasses[type.pluralize] if subclass entries << subclass.new(config) else raise ConfigError.new("don't know how to build \"#{type}\" => #{config.inspect}") end end |
#used_sources ⇒ Object
62 63 64 |
# File 'lib/sdoc_all/base.rb', line 62 def used_sources @used_sources ||= [] end |
#with_env(key, value) ⇒ Object
128 129 130 131 132 133 |
# File 'lib/sdoc_all/base.rb', line 128 def with_env(key, value) old_value, ENV[key] = ENV[key], value yield ensure ENV[key] = old_value end |