Module: Annotate
- Defined in:
- lib/annotate.rb,
lib/annotate/parser.rb,
lib/annotate/helpers.rb,
lib/annotate/version.rb,
lib/annotate/constants.rb,
lib/generators/annotate/install_generator.rb
Overview
Defines the Annotate module
Defined Under Namespace
Modules: Constants, Generators Classes: Helpers, Parser
Class Method Summary collapse
- .bootstrap_rake ⇒ Object
- .eager_load(options) ⇒ Object
- .load_tasks ⇒ Object
-
.set_defaults(options = {}) ⇒ Object
Set default values that can be overridden via environment variables.
-
.setup_options(options = {}) ⇒ Object
TODO: what is the difference between this and set_defaults?.
- .version ⇒ Object
Class Method Details
.bootstrap_rake ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/annotate.rb', line 116 def self.bootstrap_rake begin require 'rake/dsl_definition' rescue StandardError => e # We might just be on an old version of Rake... warn e. exit e.status_code end require 'rake' load './Rakefile' if File.exist?('./Rakefile') begin Rake::Task[:environment].invoke rescue StandardError nil end unless defined?(Rails) # Not in a Rails project, so time to load up the parts of # ActiveSupport we need. require 'active_support' require 'active_support/core_ext/class/subclasses' require 'active_support/core_ext/string/inflections' end load_tasks Rake::Task[:set_annotation_options].invoke end |
.eager_load(options) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/annotate.rb', line 91 def self.eager_load() load_requires() require 'annotate/active_record_patch' if defined?(Rails::Application) if Rails.version.split('.').first.to_i < 3 Rails.configuration.eager_load_paths.each do |load_path| matcher = /\A#{Regexp.escape(load_path)}(.*)\.rb\Z/ Dir.glob("#{load_path}/**/*.rb").each do |file| require_dependency file.sub(matcher, '\1') end end else klass = Rails::Application.send(:subclasses).first klass.eager_load! end else [:model_dir].each do |dir| FileList["#{dir}/**/*.rb"].each do |fname| require File.(fname) end end end end |
.load_tasks ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/annotate.rb', line 81 def self.load_tasks return if @tasks_loaded Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each do |rake| load rake end @tasks_loaded = true end |
.set_defaults(options = {}) ⇒ Object
Set default values that can be overridden via environment variables.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/annotate.rb', line 25 def self.set_defaults( = {}) return if @has_set_defaults @has_set_defaults = true = ActiveSupport::HashWithIndifferentAccess.new() Constants::ALL_ANNOTATE_OPTIONS.flatten.each do |key| if .key?(key) default_value = if [key].is_a?(Array) [key].join(',') else [key] end end default_value = ENV[key.to_s] unless ENV[key.to_s].blank? ENV[key.to_s] = default_value.nil? ? nil : default_value.to_s end end |
.setup_options(options = {}) ⇒ Object
TODO: what is the difference between this and set_defaults?
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 |
# File 'lib/annotate.rb', line 49 def self.( = {}) Constants::POSITION_OPTIONS.each do |key| [key] = Annotate::Helpers.fallback(ENV.fetch(key.to_s, nil), ENV.fetch('position', nil), 'before') end Constants::FLAG_OPTIONS.each do |key| [key] = Annotate::Helpers.true?(ENV.fetch(key.to_s, nil)) end Constants::OTHER_OPTIONS.each do |key| [key] = ENV[key.to_s].blank? ? nil : ENV.fetch(key.to_s, nil) end Constants::PATH_OPTIONS.each do |key| [key] = ENV[key.to_s].blank? ? [] : ENV[key.to_s].split(',') end [:additional_file_patterns] ||= [] if [:additional_file_patterns].is_a?(String) [:additional_file_patterns] = [:additional_file_patterns].split(',') end [:model_dir] = ['app/models'] if [:model_dir].empty? [:wrapper_open] ||= [:wrapper] [:wrapper_close] ||= [:wrapper] # These were added in 2.7.0 but so this is to revert to old behavior by default [:exclude_scaffolds] = Annotate::Helpers.true?(ENV.fetch('exclude_scaffolds', 'true')) [:exclude_controllers] = Annotate::Helpers.true?(ENV.fetch('exclude_controllers', 'true')) [:exclude_helpers] = Annotate::Helpers.true?(ENV.fetch('exclude_helpers', 'true')) end |
.version ⇒ Object
4 5 6 |
# File 'lib/annotate/version.rb', line 4 def self.version '1.0.1' end |