Class: Coupdoeil::Popover::Setup

Inherits:
Object
  • Object
show all
Defined in:
app/models/coupdoeil/popover/setup.rb

Constant Summary collapse

EMPTY_PARAMS =
{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Setup

Returns a new instance of Setup.



10
11
12
13
14
# File 'app/models/coupdoeil/popover/setup.rb', line 10

def initialize(klass)
  @klass = klass
  @type = nil
  @params = EMPTY_PARAMS
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



30
31
32
33
34
35
36
37
# File 'app/models/coupdoeil/popover/setup.rb', line 30

def method_missing(method_name, *args, &)
  if klass.action_methods.include?(method_name.name)
    raise ArgumentError, "expected no arguments, given #{args.size}" if args.any?
    with_type(method_name)
  else
    super
  end
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



6
7
8
# File 'app/models/coupdoeil/popover/setup.rb', line 6

def klass
  @klass
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'app/models/coupdoeil/popover/setup.rb', line 6

def params
  @params
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'app/models/coupdoeil/popover/setup.rb', line 6

def type
  @type
end

Instance Method Details

#default_optionsObject



16
# File 'app/models/coupdoeil/popover/setup.rb', line 16

def default_options = klass.default_options_for(type)

#identifierObject



17
# File 'app/models/coupdoeil/popover/setup.rb', line 17

def identifier = "#{type}@#{klass.popover_resource_name}"

#render_in(view_context) ⇒ Object



18
# File 'app/models/coupdoeil/popover/setup.rb', line 18

def render_in(view_context) = klass.new(params, view_context).process(type)

#respond_to_missing?(method, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/coupdoeil/popover/setup.rb', line 39

def respond_to_missing?(method, include_all = false)
  klass.action_methods.include?(method.name) || super
end

#with_params(**params) ⇒ Object



25
26
27
28
# File 'app/models/coupdoeil/popover/setup.rb', line 25

def with_params(**params)
  @params = params
  self
end

#with_type(type) ⇒ Object



20
21
22
23
# File 'app/models/coupdoeil/popover/setup.rb', line 20

def with_type(type)
  @type = type
  self
end