Class: OnboardOnRails::Configuration
- Inherits:
-
Object
- Object
- OnboardOnRails::Configuration
- Defined in:
- lib/onboard_on_rails/configuration.rb
Instance Attribute Summary collapse
-
#accent_color ⇒ Object
Returns the value of attribute accent_color.
-
#admin_auth ⇒ Object
Returns the value of attribute admin_auth.
-
#current_user_method ⇒ Object
Returns the value of attribute current_user_method.
-
#default_font ⇒ Object
Returns the value of attribute default_font.
-
#registered_attributes ⇒ Object
readonly
Returns the value of attribute registered_attributes.
-
#resolve_context ⇒ Object
Returns the value of attribute resolve_context.
-
#user_class ⇒ Object
Returns the value of attribute user_class.
-
#user_locale ⇒ Object
Returns the value of attribute user_locale.
Instance Method Summary collapse
- #accent_color_dark ⇒ Object
- #accent_color_light ⇒ Object
- #accent_color_rgba(alpha) ⇒ Object
- #attributes_schema ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #register_attribute(key, type:, label:, description: nil, values: nil, &block) ⇒ Object
- #resolve_attributes(user) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
13 14 15 16 17 18 19 20 21 |
# File 'lib/onboard_on_rails/configuration.rb', line 13 def initialize @user_class = "User" @admin_auth = ->(controller) { true } @current_user_method = :current_user @accent_color = "#2d3436" @default_font = nil @user_locale = ->(user) { "ru" } @registered_attributes = {} end |
Instance Attribute Details
#accent_color ⇒ Object
Returns the value of attribute accent_color.
11 12 13 |
# File 'lib/onboard_on_rails/configuration.rb', line 11 def accent_color @accent_color end |
#admin_auth ⇒ Object
Returns the value of attribute admin_auth.
3 4 5 |
# File 'lib/onboard_on_rails/configuration.rb', line 3 def admin_auth @admin_auth end |
#current_user_method ⇒ Object
Returns the value of attribute current_user_method.
3 4 5 |
# File 'lib/onboard_on_rails/configuration.rb', line 3 def current_user_method @current_user_method end |
#default_font ⇒ Object
Returns the value of attribute default_font.
3 4 5 |
# File 'lib/onboard_on_rails/configuration.rb', line 3 def default_font @default_font end |
#registered_attributes ⇒ Object (readonly)
Returns the value of attribute registered_attributes.
4 5 6 |
# File 'lib/onboard_on_rails/configuration.rb', line 4 def registered_attributes @registered_attributes end |
#resolve_context ⇒ Object
Returns the value of attribute resolve_context.
3 4 5 |
# File 'lib/onboard_on_rails/configuration.rb', line 3 def resolve_context @resolve_context end |
#user_class ⇒ Object
Returns the value of attribute user_class.
3 4 5 |
# File 'lib/onboard_on_rails/configuration.rb', line 3 def user_class @user_class end |
#user_locale ⇒ Object
Returns the value of attribute user_locale.
3 4 5 |
# File 'lib/onboard_on_rails/configuration.rb', line 3 def user_locale @user_locale end |
Instance Method Details
#accent_color_dark ⇒ Object
44 45 46 |
# File 'lib/onboard_on_rails/configuration.rb', line 44 def accent_color_dark adjust_brightness(accent_color, -0.15) end |
#accent_color_light ⇒ Object
48 49 50 |
# File 'lib/onboard_on_rails/configuration.rb', line 48 def accent_color_light adjust_brightness(accent_color, 0.40) end |
#accent_color_rgba(alpha) ⇒ Object
52 53 54 55 |
# File 'lib/onboard_on_rails/configuration.rb', line 52 def accent_color_rgba(alpha) r, g, b = hex_to_rgb(accent_color) "rgba(#{r}, #{g}, #{b}, #{alpha})" end |
#attributes_schema ⇒ Object
37 38 39 40 41 42 |
# File 'lib/onboard_on_rails/configuration.rb', line 37 def attributes_schema registered_attributes.values.map do |attr_def| { key: attr_def.key, type: attr_def.type, label: attr_def.label, description: attr_def.description, values: attr_def.values } end end |
#register_attribute(key, type:, label:, description: nil, values: nil, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/onboard_on_rails/configuration.rb', line 23 def register_attribute(key, type:, label:, description: nil, values: nil, &block) raise ArgumentError, "Block required for attribute #{key}" unless block_given? @registered_attributes[key] = AttributeDefinition.new( key: key, type: type, label: label, description: description, values: values, resolver: block ) end |
#resolve_attributes(user) ⇒ Object
31 32 33 34 35 |
# File 'lib/onboard_on_rails/configuration.rb', line 31 def resolve_attributes(user) registered_attributes.each_with_object({}) do |(key, attr_def), hash| hash[key] = attr_def.resolver.call(user) end end |