Class: Railspress::Configuration
- Inherits:
-
Object
- Object
- Railspress::Configuration
- Defined in:
- lib/railspress.rb
Instance Attribute Summary collapse
-
#author_class_name ⇒ Object
Returns the value of attribute author_class_name.
-
#author_display_method ⇒ Object
Returns the value of attribute author_display_method.
-
#author_scope ⇒ Object
Returns the value of attribute author_scope.
-
#authors_enabled ⇒ Object
readonly
Returns the value of attribute authors_enabled.
-
#blog_path ⇒ Object
Returns the value of attribute blog_path.
-
#cms_enabled ⇒ Object
readonly
Returns the value of attribute cms_enabled.
-
#current_author_method ⇒ Object
Returns the value of attribute current_author_method.
-
#current_author_proc ⇒ Object
Returns the value of attribute current_author_proc.
-
#default_index_columns ⇒ Object
Returns the value of attribute default_index_columns.
-
#focal_points_enabled ⇒ Object
readonly
Returns the value of attribute focal_points_enabled.
-
#image_contexts ⇒ Object
Returns the value of attribute image_contexts.
-
#inline_editing_check ⇒ Object
Returns the value of attribute inline_editing_check.
-
#post_image_variants ⇒ Object
Returns the value of attribute post_image_variants.
-
#post_images_enabled ⇒ Object
readonly
Returns the value of attribute post_images_enabled.
-
#words_per_minute ⇒ Object
Returns the value of attribute words_per_minute.
Instance Method Summary collapse
-
#add_image_context(name, aspect:, label: nil, sizes: []) ⇒ Object
Add a single image context.
-
#enable_authors ⇒ Object
Declarative setter: config.enable_authors.
-
#enable_cms ⇒ Object
Declarative setter: config.enable_cms.
-
#enable_focal_points ⇒ Object
Declarative setter: config.enable_focal_points.
-
#enable_post_images ⇒ Object
Declarative setter: config.enable_post_images.
-
#entity_for(route_key) ⇒ Object
Find entity config by route key - resolves fresh on each call.
-
#entity_registered?(route_key) ⇒ Boolean
Check if an entity is registered.
-
#entity_registrations ⇒ Object
Entity registrations: route_key => { class_name:, options: } We store class names (strings), not config objects, so Rails reloading works.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#register_entity(identifier, options = {}) ⇒ Object
Register a host model as a CMS-managed entity.
-
#registered_entities ⇒ Object
Get all registered entities - resolves fresh on each call.
-
#remove_image_context(name) ⇒ Object
Remove an image context.
-
#validate! ⇒ Object
Validate configuration after the configure block completes.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/railspress.rb', line 23 def initialize @authors_enabled = false @post_images_enabled = false @focal_points_enabled = false @cms_enabled = false @image_contexts = default_image_contexts @post_image_variants = {} @inline_editing_check = nil @author_class_name = "User" @current_author_method = :current_user @current_author_proc = nil @author_scope = nil @author_display_method = :name @words_per_minute = 200 @blog_path = "/blog" @default_index_columns = [ :id, :title, :name, :created_at ] end |
Instance Attribute Details
#author_class_name ⇒ Object
Returns the value of attribute author_class_name.
10 11 12 |
# File 'lib/railspress.rb', line 10 def @author_class_name end |
#author_display_method ⇒ Object
Returns the value of attribute author_display_method.
10 11 12 |
# File 'lib/railspress.rb', line 10 def @author_display_method end |
#author_scope ⇒ Object
Returns the value of attribute author_scope.
10 11 12 |
# File 'lib/railspress.rb', line 10 def @author_scope end |
#authors_enabled ⇒ Object (readonly)
Returns the value of attribute authors_enabled.
21 22 23 |
# File 'lib/railspress.rb', line 21 def @authors_enabled end |
#blog_path ⇒ Object
Returns the value of attribute blog_path.
10 11 12 |
# File 'lib/railspress.rb', line 10 def blog_path @blog_path end |
#cms_enabled ⇒ Object (readonly)
Returns the value of attribute cms_enabled.
21 22 23 |
# File 'lib/railspress.rb', line 21 def cms_enabled @cms_enabled end |
#current_author_method ⇒ Object
Returns the value of attribute current_author_method.
10 11 12 |
# File 'lib/railspress.rb', line 10 def @current_author_method end |
#current_author_proc ⇒ Object
Returns the value of attribute current_author_proc.
10 11 12 |
# File 'lib/railspress.rb', line 10 def @current_author_proc end |
#default_index_columns ⇒ Object
Returns the value of attribute default_index_columns.
10 11 12 |
# File 'lib/railspress.rb', line 10 def default_index_columns @default_index_columns end |
#focal_points_enabled ⇒ Object (readonly)
Returns the value of attribute focal_points_enabled.
21 22 23 |
# File 'lib/railspress.rb', line 21 def focal_points_enabled @focal_points_enabled end |
#image_contexts ⇒ Object
Returns the value of attribute image_contexts.
21 22 23 |
# File 'lib/railspress.rb', line 21 def image_contexts @image_contexts end |
#inline_editing_check ⇒ Object
Returns the value of attribute inline_editing_check.
10 11 12 |
# File 'lib/railspress.rb', line 10 def inline_editing_check @inline_editing_check end |
#post_image_variants ⇒ Object
Returns the value of attribute post_image_variants.
10 11 12 |
# File 'lib/railspress.rb', line 10 def post_image_variants @post_image_variants end |
#post_images_enabled ⇒ Object (readonly)
Returns the value of attribute post_images_enabled.
21 22 23 |
# File 'lib/railspress.rb', line 21 def post_images_enabled @post_images_enabled end |
#words_per_minute ⇒ Object
Returns the value of attribute words_per_minute.
10 11 12 |
# File 'lib/railspress.rb', line 10 def words_per_minute @words_per_minute end |
Instance Method Details
#add_image_context(name, aspect:, label: nil, sizes: []) ⇒ Object
Add a single image context
76 77 78 79 80 81 82 |
# File 'lib/railspress.rb', line 76 def add_image_context(name, aspect:, label: nil, sizes: []) @image_contexts[name.to_sym] = { aspect: aspect, label: label || name.to_s.humanize, sizes: sizes } end |
#enable_authors ⇒ Object
Declarative setter: config.enable_authors
42 43 44 |
# File 'lib/railspress.rb', line 42 def @authors_enabled = true end |
#enable_cms ⇒ Object
Declarative setter: config.enable_cms
57 58 59 |
# File 'lib/railspress.rb', line 57 def enable_cms @cms_enabled = true end |
#enable_focal_points ⇒ Object
Declarative setter: config.enable_focal_points
52 53 54 |
# File 'lib/railspress.rb', line 52 def enable_focal_points @focal_points_enabled = true end |
#enable_post_images ⇒ Object
Declarative setter: config.enable_post_images
47 48 49 |
# File 'lib/railspress.rb', line 47 def enable_post_images @post_images_enabled = true end |
#entity_for(route_key) ⇒ Object
Find entity config by route key - resolves fresh on each call
146 147 148 149 150 151 |
# File 'lib/railspress.rb', line 146 def entity_for(route_key) registration = entity_registrations[route_key.to_s] return nil unless registration resolve_entity(registration[:class_name], registration[:options]) end |
#entity_registered?(route_key) ⇒ Boolean
Check if an entity is registered
154 155 156 |
# File 'lib/railspress.rb', line 154 def entity_registered?(route_key) entity_registrations.key?(route_key.to_s) end |
#entity_registrations ⇒ Object
Entity registrations: route_key => { class_name:, options: } We store class names (strings), not config objects, so Rails reloading works
131 132 133 |
# File 'lib/railspress.rb', line 131 def entity_registrations @entity_registrations ||= {} end |
#register_entity(identifier, options = {}) ⇒ Object
Register a host model as a CMS-managed entity
Accepts class, string, or symbol. String/symbol registration is preferred for Rails reloader compatibility in development.
Registration is deferred until first access - this allows registration in initializers before models are loaded by Zeitwerk.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/railspress.rb', line 112 def register_entity(identifier, = {}) # Normalize to class name string class_name = case identifier when String then identifier when Symbol then identifier.to_s.camelize when Class then identifier.name else raise ArgumentError, "Expected String, Symbol, or Class, got #{identifier.class}" end # Compute route_key from class name (e.g., "Project" -> "projects") route_key = class_name.underscore.pluralize # Store just the class name and options - resolved fresh on each access entity_registrations[route_key] = { class_name: class_name, options: } end |
#registered_entities ⇒ Object
Get all registered entities - resolves fresh on each call
136 137 138 139 140 141 142 143 |
# File 'lib/railspress.rb', line 136 def registered_entities result = {} entity_registrations.each do |route_key, registration| config = resolve_entity(registration[:class_name], registration[:options]) result[route_key] = config if config end result end |
#remove_image_context(name) ⇒ Object
Remove an image context
85 86 87 |
# File 'lib/railspress.rb', line 85 def remove_image_context(name) @image_contexts.delete(name.to_sym) end |
#validate! ⇒ Object
Validate configuration after the configure block completes. This keeps the configure block order-independent.
63 64 65 66 67 68 |
# File 'lib/railspress.rb', line 63 def validate! if @inline_editing_check && !@cms_enabled raise Railspress::ConfigurationError, "Inline editing requires CMS. Add `config.enable_cms` to your initializer." end end |