Class: Pageflow::WidgetTypes

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pageflow/widget_types.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWidgetTypes

Returns a new instance of WidgetTypes.



7
8
9
# File 'lib/pageflow/widget_types.rb', line 7

def initialize
  clear
end

Instance Attribute Details

#defaults_by_roleObject (readonly)

Returns the value of attribute defaults_by_role.



5
6
7
# File 'lib/pageflow/widget_types.rb', line 5

def defaults_by_role
  @defaults_by_role
end

Instance Method Details

#clearObject



24
25
26
27
28
# File 'lib/pageflow/widget_types.rb', line 24

def clear
  @widget_types = {}
  @defaults_by_role = {}
  @default_configurations = {}
end

#default_configuration(name) ⇒ Object



44
45
46
# File 'lib/pageflow/widget_types.rb', line 44

def default_configuration(name)
  @default_configurations[name]
end

#each(&block) ⇒ Object



30
31
32
# File 'lib/pageflow/widget_types.rb', line 30

def each(&block)
  @widget_types.values.each(&block)
end

#fetch_by_name(name, &block) ⇒ Object



40
41
42
# File 'lib/pageflow/widget_types.rb', line 40

def fetch_by_name(name, &block)
  @widget_types.fetch(name, &block)
end

#find_all_by_role(role) ⇒ Object



48
49
50
51
52
# File 'lib/pageflow/widget_types.rb', line 48

def find_all_by_role(role)
  select do |widget_type|
    widget_type.roles.include?(role)
  end
end

#find_by_name!(name) ⇒ Object



34
35
36
37
38
# File 'lib/pageflow/widget_types.rb', line 34

def find_by_name!(name)
  fetch_by_name(name) do
    raise(WidgetType::NotFoundError, "Unknown widget type with name '#{name}'.")
  end
end

#register(widget_type, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/pageflow/widget_types.rb', line 11

def register(widget_type, options = {})
  @widget_types[widget_type.name] = widget_type
  if options[:default]
    widget_type.roles.each do |role|
      defaults_by_role[role] = widget_type
    end
  end
end

#register_widget_defaults(widget_role, default_configurations) ⇒ Object



20
21
22
# File 'lib/pageflow/widget_types.rb', line 20

def register_widget_defaults(widget_role, default_configurations)
  @default_configurations[widget_role] = default_configurations
end

#rolesObject



54
55
56
# File 'lib/pageflow/widget_types.rb', line 54

def roles
  @widget_types.values.flat_map(&:roles).uniq
end