class Arpa::Entities::Resource
Attributes
actions[R]
created_at[R]
full_name[R]
id[R]
name[R]
updated_at[R]
Public Class Methods
new(attrs = {})
click to toggle source
# File lib/arpa/entities/resource.rb, line 6 def initialize(attrs = {}) attrs = attrs.with_indifferent_access @id = attrs[:id] @full_name = attrs[:full_name] @name = attrs[:name] @created_at = attrs[:created_at] @updated_at = attrs[:updated_at] @actions = attrs[:actions].present? ? attrs[:actions] : [] end
Public Instance Methods
build_correct_name()
click to toggle source
# File lib/arpa/entities/resource.rb, line 17 def build_correct_name name = remove_word(full_name) @name = adjust_name(name) end
Private Instance Methods
adjust_name(name)
click to toggle source
# File lib/arpa/entities/resource.rb, line 24 def adjust_name(name) parts_of_name = name.split '::' refactored_name = '' parts_of_name.each_with_index do |part, index| refactored_name << '/' if index.positive? refactored_name << change_to_snake_case(part) end refactored_name end
change_to_snake_case(name)
click to toggle source
# File lib/arpa/entities/resource.rb, line 42 def change_to_snake_case(name) parts_of_name = name.split(/(?=[A-Z])/) # Split at CamelCase refactored_name = '' parts_of_name.each_with_index do |part, index| part.downcase! refactored_name << '_' if index.positive? refactored_name << part end refactored_name end
remove_word(word, word_to_delete = 'Controller')
click to toggle source
# File lib/arpa/entities/resource.rb, line 36 def remove_word(word, word_to_delete = 'Controller') word = "#{word}del" if word.include?(word_to_delete) word.slice!("#{word_to_delete}del") word end