Class: Shaf::Yard::ProfileMethodHandler

Inherits:
BaseMethodHandler
  • Object
show all
Includes:
Utils
Defined in:
lib/shaf/yard/profile_method_handler.rb

Overview

Handles call to Shaf::Serializer::profile

Constant Summary

Constants included from Utils

Utils::SHAF_VERSION_FILE

Instance Method Summary collapse

Methods included from Utils

#bootstrap, deep_symbolize_keys, deep_transform_keys, deep_transform_values, environment, gem_root, iana_link_relations, #in_project_root, #in_project_root?, #is_project_root?, model_name, pluralize, #project_root, #project_root!, rackify_header, read_config, #read_shaf_file, #read_shaf_file!, #read_shaf_upgrade_failure_version, #read_shaf_version, singularize, symbol_or_quoted_string, symbol_string, #write_shaf_file, #write_shaf_file!, #write_shaf_upgrade_failure, #write_shaf_version

Methods inherited from BaseMethodHandler

#name, #serializer_namespace

Instance Method Details

#objectObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/shaf/yard/profile_method_handler.rb', line 34

def object
  # Put the Profile object on the the same namespace level as
  # the serializer. Typically this it the root namespace
  ns = namespace.namespace

  name = shaf_profile&.to_s || self.name
  name.gsub!(/(Shaf|Profiles)?::/, "")

  name << "Profile" unless name.end_with? "Profile"

  ProfileObject.new(ns, name).tap do |obj|
    obj.dynamic = true
    obj.profile = shaf_profile
  end
end

#processObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/shaf/yard/profile_method_handler.rb', line 15

def process
  serializer = serializer_namespace
  profile = shaf_profile
  return unless serializer

  serializer.profile = profile

  register object
  serializer_namespace.profile_objects << object
end

#shaf_profileObject



26
27
28
29
30
31
32
# File 'lib/shaf/yard/profile_method_handler.rb', line 26

def shaf_profile
  return @shaf_profile if defined? @shaf_profile

  bootstrap(env: ENV['RACK_ENV'])

  @shaf_profile = Shaf::Profiles.find name
end