Class: Txray::Classifier
- Inherits:
-
Object
- Object
- Txray::Classifier
- Defined in:
- lib/txray/classifier.rb
Instance Method Summary collapse
- #call(node) ⇒ Object
- #constant_rule(constant) ⇒ Object
- #constructor?(node, name = node.name) ⇒ Boolean
-
#initialize(config) ⇒ Classifier
constructor
A new instance of Classifier.
- #iteration?(node) ⇒ Boolean
Constructor Details
#initialize(config) ⇒ Classifier
Returns a new instance of Classifier.
5 6 7 8 |
# File 'lib/txray/classifier.rb', line 5 def initialize(config) @config = config @clients = Catalog::SERVICE_NAMESPACES + config.external_clients end |
Instance Method Details
#call(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/txray/classifier.rb', line 10 def call(node) return "shell-in-transaction" if node.is_a?(Prism::XStringNode) return nil unless node.is_a?(Prism::CallNode) name = node.name constant = NodeHelpers.constant_name(node.receiver) return "shell-in-transaction" if shell?(node, name, constant) return "sleep-in-transaction" if blocking?(node, name, constant) return "mail-in-transaction" if Catalog::MAIL_METHODS.include?(name) return "job-enqueue-in-transaction" if enqueue?(name, constant) return "broadcast-in-transaction" if broadcast?(node, name) return "upload-in-transaction" if Catalog::ATTACHMENT_METHODS.include?(name) return "external-service-in-transaction" if Catalog::SEARCH_METHODS.include?(name) return "dynamic-dispatch-in-transaction" if unresolvable_dispatch?(node, name) return "cache-in-transaction" if rails_cache?(node) return nil if constructor?(node, name) constant_rule(constant) || implicit_http(name, constant) end |
#constant_rule(constant) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/txray/classifier.rb', line 31 def constant_rule(constant) return nil if constant.nil? return "http-in-transaction" if Catalog.namespaced?(constant, Catalog::HTTP_NAMESPACES) return "cache-in-transaction" if Catalog.namespaced?(constant, Catalog::CACHE_NAMESPACES) return "blocking-io-in-transaction" if Catalog.namespaced?(constant, Catalog::MEDIA_NAMESPACES) return "external-service-in-transaction" if Catalog.namespaced?(constant, @clients) nil end |
#constructor?(node, name = node.name) ⇒ Boolean
50 51 52 |
# File 'lib/txray/classifier.rb', line 50 def constructor?(node, name = node.name) Catalog::CONSTRUCTOR_METHODS.include?(name) && !constant_rule(NodeHelpers.constant_name(node.receiver)).nil? end |
#iteration?(node) ⇒ Boolean
41 42 43 44 45 46 47 48 |
# File 'lib/txray/classifier.rb', line 41 def iteration?(node) return false unless node.is_a?(Prism::CallNode) && node.block && Catalog::ITERATOR_METHODS.include?(node.name) NodeHelpers.each_node(NodeHelpers.block_body(node)) do |child| return true if child.is_a?(Prism::CallNode) && Catalog::PERSISTENCE_METHODS.include?(child.name) end false end |