Class: Pageflow::WidgetTypes
- Inherits:
-
Object
- Object
- Pageflow::WidgetTypes
- Includes:
- Enumerable
- Defined in:
- lib/pageflow/widget_types.rb
Instance Attribute Summary collapse
-
#defaults_by_role ⇒ Object
readonly
Returns the value of attribute defaults_by_role.
Instance Method Summary collapse
- #clear ⇒ Object
- #default_configuration(name) ⇒ Object
- #each(&block) ⇒ Object
- #fetch_by_name(name, &block) ⇒ Object
- #find_all_by_role(role) ⇒ Object
- #find_by_name!(name) ⇒ Object
-
#initialize ⇒ WidgetTypes
constructor
A new instance of WidgetTypes.
- #register(widget_type, options = {}) ⇒ Object
- #register_widget_defaults(widget_role, default_configurations) ⇒ Object
- #roles ⇒ Object
- #type_name?(name) ⇒ Boolean
Constructor Details
#initialize ⇒ WidgetTypes
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_role ⇒ Object (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
#clear ⇒ Object
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
48 49 50 |
# File 'lib/pageflow/widget_types.rb', line 48 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
52 53 54 55 56 |
# File 'lib/pageflow/widget_types.rb', line 52 def find_all_by_role(role) select do || .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_types[.name] = if [:default] .roles.each do |role| defaults_by_role[role] = end end end |
#register_widget_defaults(widget_role, default_configurations) ⇒ Object
20 21 22 |
# File 'lib/pageflow/widget_types.rb', line 20 def (, default_configurations) @default_configurations[] = default_configurations end |
#roles ⇒ Object
58 59 60 |
# File 'lib/pageflow/widget_types.rb', line 58 def roles @widget_types.values.flat_map(&:roles).uniq end |
#type_name?(name) ⇒ Boolean
44 45 46 |
# File 'lib/pageflow/widget_types.rb', line 44 def type_name?(name) @widget_types.key?(name) end |