class Pakyow::Reflection::Scope

@api private

Attributes

actions[R]
children[R]
name[R]
parent[W]
parents[R]

Public Class Methods

new(name) click to toggle source
# File lib/pakyow/reflection/scope.rb, line 12
def initialize(name)
  @name = normalize(name)
  @parents, @actions, @attributes, @children = [], [], { form: [], view: [] }, []
end

Public Instance Methods

action(name) click to toggle source
# File lib/pakyow/reflection/scope.rb, line 28
def action(name)
  @actions.find { |action|
    action.named?(name)
  }
end
add_attribute(attribute, type:) click to toggle source
# File lib/pakyow/reflection/scope.rb, line 40
def add_attribute(attribute, type:)
  @attributes[type] << attribute
end
add_parent(parent) click to toggle source
# File lib/pakyow/reflection/scope.rb, line 17
def add_parent(parent)
  unless @parents.include?(parent)
    @parents << parent
    parent.children << self
  end
end
attribute(name, type:) click to toggle source
# File lib/pakyow/reflection/scope.rb, line 34
def attribute(name, type:)
  @attributes[type].find { |attribute|
    attribute.named?(name)
  }
end
attributes() click to toggle source
# File lib/pakyow/reflection/scope.rb, line 44
def attributes
  # TODO: In addition to finding view attributes, should we be finding view associations?
  #
  @attributes[:form].concat(@attributes[:view]).uniq { |attribute|
    attribute.name
  }
end
cleanup() click to toggle source
# File lib/pakyow/reflection/scope.rb, line 56
def cleanup
  @actions.each(&:cleanup)
end
named?(name) click to toggle source
# File lib/pakyow/reflection/scope.rb, line 24
def named?(name)
  @name == normalize(name)
end
plural_name() click to toggle source
# File lib/pakyow/reflection/scope.rb, line 52
def plural_name
  Support.inflector.pluralize(@name).to_sym
end

Private Instance Methods

normalize(name) click to toggle source
# File lib/pakyow/reflection/scope.rb, line 62
def normalize(name)
  Support.inflector.singularize(name.to_s).to_sym
end