Class: ActionAdmin::Shortcode

Inherits:
Object
  • Object
show all
Defined in:
lib/action_admin/shortcode.rb

Instance Method Summary collapse

Constructor Details

#initialize(params, attribs = {}) ⇒ Shortcode

Initializes the decorator



4
5
6
7
8
9
10
# File 'lib/action_admin/shortcode.rb', line 4

def initialize(params, attribs={})
  attribs = Hash[attribs.map { |k, _v| [k, nil] }].symbolize_keys
  string  = URI.decode(params[:shortcode])

  @field  = params[:id]
  @object = parse_shortcode_attr(string, attribs)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegates to the wrapped object



18
19
20
21
22
23
24
# File 'lib/action_admin/shortcode.rb', line 18

def method_missing(method, *args, &block)
  if @object.key? method
    @object[method]
  elsif @object.respond_to? method
    @object.send(method, *args, &block)
  end
end

Instance Method Details

#has_attribute?(attribute) ⇒ Boolean

Check if attribute exists

Returns:

  • (Boolean)


27
28
29
# File 'lib/action_admin/shortcode.rb', line 27

def has_attribute?(attribute)
  @object.key? attribute
end

#model_nameObject

Sets the model name



13
14
15
# File 'lib/action_admin/shortcode.rb', line 13

def model_name
  ActiveModel::Name.new(self.class, nil, @field)
end