Class: AwesomeAnnotate::Configuration
- Inherits:
-
Object
- Object
- AwesomeAnnotate::Configuration
- Defined in:
- lib/awesome_annotate/configuration.rb
Constant Summary collapse
- DEFAULT_PATH =
'config/initializers/awesome_annotate.yml'- DEFAULT_OPTIONS =
{ env_file_path: 'config/environment.rb', model_dir: 'app/models', route_file_path: 'config/routes.rb', annotation_position: 'top', exclude_model_files: [], include_indexes: true, exclude_columns: [], include_column_defaults: true, exclude_routes: [] }.freeze
- ANNOTATION_POSITIONS =
%w[top bottom].freeze
- TEMPLATE =
<<~YAML # AwesomeAnnotate configuration # # Change these paths when your Rails app uses non-standard locations. env_file_path: config/environment.rb model_dir: app/models route_file_path: config/routes.rb annotation_position: top exclude_model_files: [] include_indexes: true exclude_columns: [] include_column_defaults: true exclude_routes: [] YAML
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
64 65 66 67 68 69 70 71 72 |
# File 'lib/awesome_annotate/configuration.rb', line 64 def initialize( = {}) @options = DEFAULT_OPTIONS.merge() validate_annotation_position validate_exclude_model_files validate_include_indexes validate_exclude_columns validate_include_column_defaults validate_exclude_routes end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
62 63 64 |
# File 'lib/awesome_annotate/configuration.rb', line 62 def @options end |
Class Method Details
.create(path = DEFAULT_PATH) ⇒ Object
47 48 49 50 |
# File 'lib/awesome_annotate/configuration.rb', line 47 def create(path = DEFAULT_PATH) FileUtils.mkdir_p(File.dirname(path)) File.write(path, TEMPLATE) end |
.load(path = DEFAULT_PATH) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/awesome_annotate/configuration.rb', line 38 def load(path = DEFAULT_PATH) return new unless File.exist?(path) loaded = YAML.safe_load_file(path, aliases: false) || {} raise ArgumentError, "Configuration file must contain a YAML mapping: #{path}" unless loaded.is_a?(Hash) new((loaded)) end |