Class: Tramway::Configs::Entity

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/tramway/configs/entity.rb

Overview

Tramway is an entity-based framework

Defined Under Namespace

Classes: HumanNameStruct, RouteStruct

Constant Summary collapse

ACTIONS =

Route Struct contains implemented in Tramway CRUD and helpful routes for the entity

i[index show new create edit update destroy].freeze

Instance Method Summary collapse

Instance Method Details

#create_helper_methodObject



54
55
56
# File 'lib/tramway/configs/entity.rb', line 54

def create_helper_method
  build_helper_method(name, route:, namespace:, plural: true)
end

#destroy_helper_methodObject



66
67
68
# File 'lib/tramway/configs/entity.rb', line 66

def destroy_helper_method
  build_helper_method(name, route:, namespace:, plural: false)
end

#edit_helper_methodObject



58
59
60
# File 'lib/tramway/configs/entity.rb', line 58

def edit_helper_method
  build_helper_method(name, route:, namespace:, plural: false, action: :edit)
end

#human_nameObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tramway/configs/entity.rb', line 26

def human_name
  if model_class.present?
    model_name = model_class.model_name.human

    [model_name, pluralized(model_name)]
  else
    [name.capitalize, name.pluralize.capitalize]
  end => single, plural

  HumanNameStruct.new(single, plural)
end

#index_helper_methodObject



46
47
48
# File 'lib/tramway/configs/entity.rb', line 46

def index_helper_method
  build_helper_method(name, route:, namespace:, plural: true)
end

#model_classObject



70
71
72
73
74
# File 'lib/tramway/configs/entity.rb', line 70

def model_class
  name.classify.constantize
rescue StandardError
  nil
end

#new_helper_methodObject



50
51
52
# File 'lib/tramway/configs/entity.rb', line 50

def new_helper_method
  build_helper_method(name, route:, namespace:, plural: false, action: :new)
end

#page(name) ⇒ Object Also known as: set_page?



38
39
40
# File 'lib/tramway/configs/entity.rb', line 38

def page(name)
  pages.find { |page| page.action == name.to_s }
end

#routesObject



22
23
24
# File 'lib/tramway/configs/entity.rb', line 22

def routes
  RouteStruct.new(*route_helper_methods)
end

#show_helper_methodObject



42
43
44
# File 'lib/tramway/configs/entity.rb', line 42

def show_helper_method
  build_helper_method(name, route:, namespace:, plural: false)
end

#update_helper_methodObject



62
63
64
# File 'lib/tramway/configs/entity.rb', line 62

def update_helper_method
  build_helper_method(name, route:, namespace:, plural: false)
end