Module: Pavlov
- Defined in:
- lib/pavlov.rb,
lib/pavlov/query.rb,
lib/pavlov/engine.rb,
lib/pavlov/command.rb,
lib/pavlov/helpers.rb,
lib/pavlov/version.rb,
lib/pavlov/operation.rb,
lib/pavlov/interactor.rb,
lib/pavlov/validations.rb,
lib/pavlov/access_denied.rb,
lib/pavlov/validation_error.rb,
lib/pavlov/alpha_compatibility.rb,
lib/generators/pavlov/install_generator.rb
Defined Under Namespace
Modules: Command, Helpers, Interactor, Operation, Query, Validations
Classes: AccessDenied, Engine, InstallGenerator, ValidationError
Constant Summary
collapse
- VERSION =
We’re doing this because we might write tests that deal with other versions of bundler and we are unsure how to handle this better.
"0.1.3"
Class Method Summary
collapse
Class Method Details
.arguments_to_attributes(operation_class, arguments) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/pavlov/alpha_compatibility.rb', line 25
def self.arguments_to_attributes(operation_class, arguments)
attribute_keys = operation_class.attribute_set.map(&:name)
hash={}
arguments.each_with_index do |value, index|
hash[attribute_keys[index].to_sym] = value
end
return hash
end
|
.command(command_name, *args) ⇒ Object
12
13
14
15
16
|
# File 'lib/pavlov.rb', line 12
def self.command command_name, *args
class_name = "Commands::"+string_to_classname(command_name)
klass = get_class_by_string(class_name)
klass.new(*args).call
end
|
.get_class_by_string(classname) ⇒ Object
this method is also available as constantize in Rails, but we want to be able to write classes and/or tests without Rails
4
5
6
|
# File 'lib/pavlov.rb', line 4
def self.get_class_by_string classname
classname.constantize
end
|
.interactor(command_name, *args) ⇒ Object
18
19
20
21
22
|
# File 'lib/pavlov.rb', line 18
def self.interactor command_name, *args
class_name = "Interactors::"+string_to_classname(command_name)
klass = get_class_by_string class_name
klass.new(*args).call
end
|
.old_command(command_name, *args) ⇒ Object
4
5
6
7
8
9
|
# File 'lib/pavlov/alpha_compatibility.rb', line 4
def self.old_command command_name, *args
class_name = "Commands::"+string_to_classname(command_name)
klass = get_class_by_string(class_name)
attributes = arguments_to_attributes(klass, args)
klass.new(attributes).call
end
|
.old_interactor(command_name, *args) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/pavlov/alpha_compatibility.rb', line 11
def self.old_interactor command_name, *args
class_name = "Interactors::"+string_to_classname(command_name)
klass = get_class_by_string class_name
attributes = arguments_to_attributes(klass, args)
klass.new(attributes).call
end
|
.old_query(command_name, *args) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/pavlov/alpha_compatibility.rb', line 18
def self.old_query command_name, *args
class_name = "Queries::"+string_to_classname(command_name)
klass = get_class_by_string class_name
attributes = arguments_to_attributes(klass, args)
klass.new(attributes).call
end
|
.query(command_name, *args) ⇒ Object
24
25
26
27
28
|
# File 'lib/pavlov.rb', line 24
def self.query command_name, *args
class_name = "Queries::"+string_to_classname(command_name)
klass = get_class_by_string class_name
klass.new(*args).call
end
|
.string_to_classname(string) ⇒ Object
8
9
10
|
# File 'lib/pavlov.rb', line 8
def self.string_to_classname string
string.to_s.camelize
end
|