Class: OnboardOnRails::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/onboard_on_rails/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_colorObject

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_authObject

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_methodObject

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_fontObject

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_attributesObject (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_contextObject

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_classObject

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_localeObject

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_darkObject



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_lightObject



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_schemaObject



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

Raises:

  • (ArgumentError)


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