Class: Serega::SeregaPlugins::CamelCase::CamelCaseConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/serega/plugins/camel_case/camel_case.rb

Overview

CamelCase config object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Serega::SeregaPlugins::CamelCase::CamelCaseConfig

Initializes CamelCaseConfig object

Parameters:

  • opts (Hash)

    camel_case plugin options

Options Hash (opts):

  • :transform (#call)

    Callable object that transforms original attribute name



163
164
165
# File 'lib/serega/plugins/camel_case/camel_case.rb', line 163

def initialize(opts)
  @opts = opts
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



153
154
155
# File 'lib/serega/plugins/camel_case/camel_case.rb', line 153

def opts
  @opts
end

Instance Method Details

#transform#call

Returns defined object that transforms name.

Returns:

  • (#call)

    defined object that transforms name



168
169
170
# File 'lib/serega/plugins/camel_case/camel_case.rb', line 168

def transform
  opts.fetch(:transform)
end

#transform=(value) ⇒ #call

Sets transformation callable object

Parameters:

  • value (#call)

    transformation

Returns:

  • (#call)

    camel_case plugin transformation callable object

Raises:



177
178
179
180
181
182
183
184
185
186
# File 'lib/serega/plugins/camel_case/camel_case.rb', line 177

def transform=(value)
  raise SeregaError, "Transform value must respond to #call" unless value.respond_to?(:call)

  params = value.is_a?(Proc) ? value.parameters : value.method(:call).parameters
  if params.count != 1 || !params.all? { |param| (param[0] == :req) || (param[0] == :opt) }
    raise SeregaError, "Transform value must respond to #call and accept 1 regular parameter"
  end

  opts[:transform] = value
end