Class: Refinery::Widgets::WidgetType

Inherits:
Object
  • Object
show all
Defined in:
lib/refinery/widgets/widget_type.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_as_string) ⇒ WidgetType

Returns a new instance of WidgetType.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/refinery/widgets/widget_type.rb', line 9

def initialize(class_as_string)
  if class_as_string.is_a?(Hash)
    attributes = class_as_string.dup
    class_as_string = attributes[:name]
    description = attributes[:description]
  end
  @klass_as_string = class_as_string
  @klass = class_as_string.constantize
  @html_id = class_as_string.split('::').last.underscore
  @association_name = @html_id
  @attribute_param = "#{@association_name}_attributes"
  @admin_partial = @html_id
  @admin_preview_partial = "#{@html_id}_preview"
  @front_partial = @html_id
  @name = @html_id.humanize
  @description = description || ''
end

Instance Attribute Details

#admin_partialObject (readonly)

Returns the value of attribute admin_partial.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def admin_partial
  @admin_partial
end

#admin_preview_partialObject (readonly)

Returns the value of attribute admin_preview_partial.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def admin_preview_partial
  @admin_preview_partial
end

#association_nameObject (readonly)

Returns the value of attribute association_name.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def association_name
  @association_name
end

#attribute_paramObject (readonly)

Returns the value of attribute attribute_param.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def attribute_param
  @attribute_param
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def description
  @description
end

#front_partialObject (readonly)

Returns the value of attribute front_partial.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def front_partial
  @front_partial
end

#html_idObject (readonly)

Returns the value of attribute html_id.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def html_id
  @html_id
end

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def klass
  @klass
end

#klass_as_stringObject (readonly)

Returns the value of attribute klass_as_string.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def klass_as_string
  @klass_as_string
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/refinery/widgets/widget_type.rb', line 5

def name
  @name
end

Class Method Details

.allObject



27
28
29
30
# File 'lib/refinery/widgets/widget_type.rb', line 27

def self.all
  Refinery::Widgets.config[:base_widgets].collect{|w| self.new(w) } + 
  Refinery::Widgets.config[:additional_widgets].collect{|w| self.new(w) }
end

.find(class_as_string) ⇒ Object



32
33
34
# File 'lib/refinery/widgets/widget_type.rb', line 32

def self.find(class_as_string)
  self.new(class_as_string)
end