Class: MuchRails::Action::MuchRailsActionConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/much-rails/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMuchRailsActionConfig

Returns a new instance of MuchRailsActionConfig.



308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/much-rails/action.rb', line 308

def initialize
  @params_root = nil
  @required_params = []
  @date_params = []
  @time_params = []
  @boolean_params = []

  @format = nil

  @on_validation_blocks = []
  @on_before_call_blocks = []
  @on_after_call_blocks = []
  @on_call_block = ->{}
end

Instance Attribute Details

#boolean_paramsObject (readonly)

Returns the value of attribute boolean_params.



305
306
307
# File 'lib/much-rails/action.rb', line 305

def boolean_params
  @boolean_params
end

#date_paramsObject (readonly)

Returns the value of attribute date_params.



304
305
306
# File 'lib/much-rails/action.rb', line 304

def date_params
  @date_params
end

#formatObject (readonly)

Returns the value of attribute format.



305
306
307
# File 'lib/much-rails/action.rb', line 305

def format
  @format
end

#on_after_call_blocksObject (readonly)

Returns the value of attribute on_after_call_blocks.



306
307
308
# File 'lib/much-rails/action.rb', line 306

def on_after_call_blocks
  @on_after_call_blocks
end

#on_before_call_blocksObject (readonly)

Returns the value of attribute on_before_call_blocks.



306
307
308
# File 'lib/much-rails/action.rb', line 306

def on_before_call_blocks
  @on_before_call_blocks
end

#on_call_blockObject (readonly)

Returns the value of attribute on_call_block.



306
307
308
# File 'lib/much-rails/action.rb', line 306

def on_call_block
  @on_call_block
end

#on_validation_blocksObject (readonly)

Returns the value of attribute on_validation_blocks.



305
306
307
# File 'lib/much-rails/action.rb', line 305

def on_validation_blocks
  @on_validation_blocks
end

#params_rootObject (readonly)

Returns the value of attribute params_root.



304
305
306
# File 'lib/much-rails/action.rb', line 304

def params_root
  @params_root
end

#required_paramsObject (readonly)

Returns the value of attribute required_params.



304
305
306
# File 'lib/much-rails/action.rb', line 304

def required_params
  @required_params
end

#time_paramsObject (readonly)

Returns the value of attribute time_params.



304
305
306
# File 'lib/much-rails/action.rb', line 304

def time_params
  @time_params
end

Instance Method Details

#add_boolean_params(klass, param_names) ⇒ Object



351
352
353
354
355
356
357
358
359
360
361
# File 'lib/much-rails/action.rb', line 351

def add_boolean_params(klass, param_names)
  Array.wrap(param_names).tap do |names|
    @boolean_params.concat(names)

    names.each do |name|
      klass.public_send(
        :define_method, "#{name}?", &memoize_boolean_decode(name)
      )
    end
  end
end

#add_date_params(klass, param_names) ⇒ Object



331
332
333
334
335
336
337
338
339
# File 'lib/much-rails/action.rb', line 331

def add_date_params(klass, param_names)
  Array.wrap(param_names).tap do |names|
    @date_params.concat(names)

    names.each do |name|
      klass.public_send(:define_method, name, &memoize_date_decode(name))
    end
  end
end

#add_on_after_call_block(block) ⇒ Object



379
380
381
# File 'lib/much-rails/action.rb', line 379

def add_on_after_call_block(block)
  @on_after_call_blocks << block
end

#add_on_before_call_block(block) ⇒ Object



375
376
377
# File 'lib/much-rails/action.rb', line 375

def add_on_before_call_block(block)
  @on_before_call_blocks << block
end

#add_on_validation_block(block) ⇒ Object



367
368
369
# File 'lib/much-rails/action.rb', line 367

def add_on_validation_block(block)
  @on_validation_blocks << block
end

#add_required_params(param_names) ⇒ Object



327
328
329
# File 'lib/much-rails/action.rb', line 327

def add_required_params(param_names)
  @required_params.concat(Array.wrap(param_names))
end

#add_time_params(klass, param_names) ⇒ Object



341
342
343
344
345
346
347
348
349
# File 'lib/much-rails/action.rb', line 341

def add_time_params(klass, param_names)
  Array.wrap(param_names).tap do |names|
    @time_params.concat(names)

    names.each do |name|
      klass.public_send(:define_method, name, &memoize_time_decode(name))
    end
  end
end

#set_format(value) ⇒ Object



363
364
365
# File 'lib/much-rails/action.rb', line 363

def set_format(value)
  @format = value
end

#set_on_call_block(block) ⇒ Object



371
372
373
# File 'lib/much-rails/action.rb', line 371

def set_on_call_block(block)
  @on_call_block = block
end

#set_params_root(value) ⇒ Object



323
324
325
# File 'lib/much-rails/action.rb', line 323

def set_params_root(value)
  @params_root = value
end