Class: Satis::Configuration
- Inherits:
-
Object
- Object
- Satis::Configuration
- Defined in:
- lib/satis/configuration.rb
Instance Attribute Summary collapse
-
#confirm_before_leave ⇒ Object
Returns the value of attribute confirm_before_leave.
- #current_user ⇒ Object
- #default_help_text(template, object, method, additional_scope) ⇒ Object
-
#logger ⇒ Object
Config: logger [Object].
-
#submit_on_enter ⇒ Object
Returns the value of attribute submit_on_enter.
Instance Method Summary collapse
-
#help_scope(template, object, additional_scope, action: nil) ⇒ Object
Maybe not the right place?.
- #help_scopes(template, object, additional_scope) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/satis/configuration.rb', line 9 def initialize @logger = Logger.new(STDOUT) @submit_on_enter = true @confirm_before_leave = false @current_user = -> {} @default_help_text = lambda do |_template, _object, key, _additional_scope| scope = help_scope(template, object, additional_scope) value = I18n.t((["help"] + scope + [key.to_s]).join(".")) if /translation missing: (.+)/.match?(value) nil else value end end end |
Instance Attribute Details
#confirm_before_leave ⇒ Object
Returns the value of attribute confirm_before_leave.
5 6 7 |
# File 'lib/satis/configuration.rb', line 5 def confirm_before_leave @confirm_before_leave end |
#current_user ⇒ Object
62 63 64 65 66 |
# File 'lib/satis/configuration.rb', line 62 def current_user raise 'current_user should be a Proc' unless @current_user.is_a? Proc instance_exec(&@current_user) end |
#default_help_text(template, object, method, additional_scope) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/satis/configuration.rb', line 33 def default_help_text(template, object, method, additional_scope) if @default_help_text.is_a?(Proc) instance_exec(template, object, method, additional_scope, &@default_help_text) else @default_help_text end end |
#logger ⇒ Object
Config: logger [Object].
29 30 31 |
# File 'lib/satis/configuration.rb', line 29 def logger @logger.is_a?(Proc) ? instance_exec(&@logger) : @logger end |
#submit_on_enter ⇒ Object
Returns the value of attribute submit_on_enter.
5 6 7 |
# File 'lib/satis/configuration.rb', line 5 def submit_on_enter @submit_on_enter end |
Instance Method Details
#help_scope(template, object, additional_scope, action: nil) ⇒ Object
Maybe not the right place?
43 44 45 46 47 48 49 50 51 |
# File 'lib/satis/configuration.rb', line 43 def help_scope(template, object, additional_scope, action: nil) scope = template.controller.controller_path.split("/") scope << (action || template.controller.action_name) scope << object.class.name.demodulize.tableize.singularize scope += Array.wrap(additional_scope) if additional_scope scope.map(&:to_s) end |
#help_scopes(template, object, additional_scope) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/satis/configuration.rb', line 53 def help_scopes(template, object, additional_scope) actions = [template.controller.action_name] %w[show new edit create update destroy index].each do |action| actions << action unless actions.include?(action) end actions.map { |action| help_scope(template, object, additional_scope, action: action) } end |