Class: Sord::ParlourPlugin
- Inherits:
-
Parlour::Plugin
- Object
- Parlour::Plugin
- Sord::ParlourPlugin
- Defined in:
- lib/sord/parlour_plugin.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parlour ⇒ Object
Returns the value of attribute parlour.
Class Method Summary collapse
Instance Method Summary collapse
- #add_custom_tags ⇒ Object
- #generate(root) ⇒ Object
-
#initialize(options) ⇒ ParlourPlugin
constructor
A new instance of ParlourPlugin.
Constructor Details
#initialize(options) ⇒ ParlourPlugin
Returns a new instance of ParlourPlugin.
10 11 12 13 14 15 16 17 18 |
# File 'lib/sord/parlour_plugin.rb', line 10 def initialize() @parlour = nil = [:sord_comments] = true if [:sord_comments].nil? [:regenerate] = true if [:regenerate].nil? [:replace_errors_with_untyped] ||= false [:replace_unresolved_with_untyped] ||= false end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/sord/parlour_plugin.rb', line 7 def end |
#parlour ⇒ Object
Returns the value of attribute parlour.
8 9 10 |
# File 'lib/sord/parlour_plugin.rb', line 8 def parlour @parlour end |
Class Method Details
.with_clean_env(&block) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/sord/parlour_plugin.rb', line 91 def self.with_clean_env &block meth = if Bundler.respond_to?(:with_unbundled_env) :with_unbundled_env else :with_clean_env end Bundler.send meth, &block end |
Instance Method Details
#add_custom_tags ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/sord/parlour_plugin.rb', line 82 def return if [:tags].empty? [:tags].each do |tag| name, description = tag.split(':') YARD::Tags::Library.define_tag(description, name) end end |
#generate(root) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sord/parlour_plugin.rb', line 20 def generate(root) if [:include_messages] && [:exclude_messages] Sord::Logging.error('Please specify only one of --include-messages and --exclude-messages.') return false elsif [:include_messages] whitelist = [:include_messages].map { |x| x.downcase.to_sym } unless Sord::Logging.valid_types?(whitelist) Sord::Logging.error('Not all types on your --include-messages list are valid.') Sord::Logging.error("Valid options are: #{Sord::Logging::AVAILABLE_TYPES.map(&:to_s).join(', ')}") return false end Sord::Logging.enabled_types = whitelist | [:done] elsif [:exclude_messages] blacklist = [:exclude_messages].map { |x| x.downcase.to_sym } unless Sord::Logging.valid_types?(blacklist) Sord::Logging.error('Not all types on your --include-messages list are valid.') Sord::Logging.error("Valid options are: #{Sord::Logging::AVAILABLE_TYPES.map(&:to_s).join(', ')}") return false end Sord::Logging.enabled_types = Sord::Logging::AVAILABLE_TYPES - blacklist end if !([:rbi] || [:rbs]) Sord::Logging.error('No output format given; please specify --rbi or --rbs') exit 1 end if ([:rbi] && [:rbs]) Sord::Logging.error('You cannot specify both --rbi and --rbs; please use only one') exit 1 end if [:regenerate] begin Sord::Logging.info('Running YARD...') Sord::ParlourPlugin.with_clean_env do tag_param = '' [:tags]&.each do |tag| tag_param += "--tag #{tag} " end system("bundle exec yard #{tag_param} --no-output") end rescue Errno::ENOENT Sord::Logging.error('The YARD tool could not be found on your PATH.') Sord::Logging.error('You may need to run \'gem install yard\'.') Sord::Logging.error('If documentation has already been generated, pass --no-regenerate to Sord.') return false end end [:mode] = \ if [:rbi] then :rbi elsif [:rbs] then :rbs end [:parlour] = @parlour [:root] = root Sord::Generator.new().run true end |