Class: Avo::Fields::GravatarField
- Defined in:
- lib/avo/app/fields/gravatar_field.rb
Instance Attribute Summary
Attributes inherited from Field
#block, #component, #computable, #default, #format_using, #help, #id, #is_array_param, #is_object_param, #name, #null_values, #nullable, #placeholder, #readonly, #required, #sortable, #updatable
Attributes included from FieldExtensions::VisibleOnDifferentViews
#show_on_create, #show_on_edit, #show_on_index, #show_on_show
Instance Method Summary collapse
- #hydrate_field(fields, model, resource, view) ⇒ Object
-
#initialize(name, **args, &block) ⇒ GravatarField
constructor
A new instance of GravatarField.
Methods inherited from Field
#database_id, #fetch_for_action, #fetch_for_resource, #fill_field, #has_own_panel?, #resolve_attribute
Methods included from FieldExtensions::HasFieldName
#field_name, #field_name_attribute, #get_field_name
Methods included from FieldExtensions::VisibleOnDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(name, **args, &block) ⇒ GravatarField
Returns a new instance of GravatarField.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/avo/app/fields/gravatar_field.rb', line 7 def initialize(name, **args, &block) @defaults = { component: 'gravatar-field', name: 'Avatar', id: args[:id].present? ? args[:id] : 'email', } super(name, **args, &block) hide_on [:edit, :create] @rounded = args[:rounded].present? ? args[:rounded] : true @size = args[:size].present? ? args[:size].to_i : 40 @default = args[:default].present? ? ERB::Util.url_encode(args[:default]).to_s : '' @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false end |
Instance Method Details
#hydrate_field(fields, model, resource, view) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/avo/app/fields/gravatar_field.rb', line 24 def hydrate_field(fields, model, resource, view) value = nil if model[id].present? value = Digest::MD5.hexdigest(model[id].strip.downcase) end { value: value, rounded: @rounded, default: @default, size: @size, link_to_resource: @link_to_resource, } end |