Class: Relaxo::Model::Key

Inherits:
Struct
  • Object
show all
Defined in:
lib/relaxo/model/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#indexObject

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



26
27
28
# File 'lib/relaxo/model/base.rb', line 26

def index
  @index
end

#prefixObject

Returns the value of attribute prefix

Returns:

  • (Object)

    the current value of prefix



26
27
28
# File 'lib/relaxo/model/base.rb', line 26

def prefix
  @prefix
end

Instance Method Details

#object_path(model, **arguments) ⇒ Object



42
43
44
# File 'lib/relaxo/model/base.rb', line 42

def object_path(model, **arguments)
	resolve(self.prefix + self.index, model, **arguments).join('/')
end

#prefix_path(model, **arguments) ⇒ Object



46
47
48
# File 'lib/relaxo/model/base.rb', line 46

def prefix_path(model, **arguments)
	resolve(self.prefix, model, **arguments).join('/')
end

#resolve(key_path, model, **arguments) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/relaxo/model/base.rb', line 27

def resolve(key_path, model, **arguments)
	key_path.collect do |component|
		case component
		when Symbol
			arguments[component] || model.send(component) || 'null'
		when Array
			resolve(component, model, arguments).join('-')
		when Proc
			model.instance_exec(**arguments, &component)
		else
			component
		end
	end
end