Class: Pakyow::Reflection::Scope Private

Inherits:
Object
  • Object
show all
Defined in:
lib/pakyow/reflection/scope.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Scope

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Scope.



12
13
14
15
# File 'lib/pakyow/reflection/scope.rb', line 12

def initialize(name)
  @name = normalize(name)
  @parents, @actions, @attributes, @children = [], [], { form: [], view: [] }, []
end

Instance Attribute Details

#actionsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/pakyow/reflection/scope.rb', line 9

def actions
  @actions
end

#childrenObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/pakyow/reflection/scope.rb', line 9

def children
  @children
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/pakyow/reflection/scope.rb', line 9

def name
  @name
end

#parent=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/pakyow/reflection/scope.rb', line 10

def parent=(value)
  @parent = value
end

#parentsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/pakyow/reflection/scope.rb', line 9

def parents
  @parents
end

Instance Method Details

#action(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
31
32
# File 'lib/pakyow/reflection/scope.rb', line 28

def action(name)
  @actions.find { |action|
    action.named?(name)
  }
end

#add_attribute(attribute, type:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/pakyow/reflection/scope.rb', line 40

def add_attribute(attribute, type:)
  @attributes[type] << attribute
end

#add_parent(parent) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
# 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:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
# File 'lib/pakyow/reflection/scope.rb', line 34

def attribute(name, type:)
  @attributes[type].find { |attribute|
    attribute.named?(name)
  }
end

#attributesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



44
45
46
47
48
49
50
# 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

#cleanupObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
# File 'lib/pakyow/reflection/scope.rb', line 56

def cleanup
  @actions.each(&:cleanup)
end

#named?(name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


24
25
26
# File 'lib/pakyow/reflection/scope.rb', line 24

def named?(name)
  @name == normalize(name)
end

#plural_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/pakyow/reflection/scope.rb', line 52

def plural_name
  Support.inflector.pluralize(@name).to_sym
end