Class: Aegis::Resource
- Inherits:
-
Object
- Object
- Aegis::Resource
- Defined in:
- lib/aegis/resource.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#never_takes_object ⇒ Object
readonly
Returns the value of attribute never_takes_object.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #action_names_with_aliases(native_name, aliases) ⇒ Object
- #action_paths(action, aliases) ⇒ Object
- #collection? ⇒ Boolean
- #create_or_update_action(name, create_options, update_options) ⇒ Object
- #find_action_by_name(name) ⇒ Object
- #index_actions_by_path(aliases) ⇒ Object
-
#initialize(parent, name, type, options) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
- #new_action_takes_object?(action_options = {}) ⇒ Boolean
- #new_action_takes_parent_object?(action_options = {}) ⇒ Boolean
- #reading_actions ⇒ Object
- #root? ⇒ Boolean
- #singleton? ⇒ Boolean
- #writing_actions ⇒ Object
Constructor Details
#initialize(parent, name, type, options) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 11 12 13 |
# File 'lib/aegis/resource.rb', line 6 def initialize(parent, name, type, ) @parent = parent @children = [] @name = name @type = type @actions = initial_actions() # @never_takes_object = options[:object] == false end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
4 5 6 |
# File 'lib/aegis/resource.rb', line 4 def actions @actions end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/aegis/resource.rb', line 4 def children @children end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/aegis/resource.rb', line 4 def name @name end |
#never_takes_object ⇒ Object (readonly)
Returns the value of attribute never_takes_object.
4 5 6 |
# File 'lib/aegis/resource.rb', line 4 def never_takes_object @never_takes_object end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
4 5 6 |
# File 'lib/aegis/resource.rb', line 4 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/aegis/resource.rb', line 4 def type @type end |
Instance Method Details
#action_names_with_aliases(native_name, aliases) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/aegis/resource.rb', line 69 def action_names_with_aliases(native_name, aliases) names = [native_name] aliases.each do |key, value| names << key if value == native_name end names end |
#action_paths(action, aliases) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/aegis/resource.rb', line 55 def action_paths(action, aliases) if root? action_names_with_aliases(action.name, aliases) else action_names_with_aliases(action.name, aliases).collect do |action_name| build_path( action_name, parent && parent.path(false), action.pluralize_resource ? name.pluralize : name.singularize ) end end end |
#collection? ⇒ Boolean
43 44 45 |
# File 'lib/aegis/resource.rb', line 43 def collection? type == :collection end |
#create_or_update_action(name, create_options, update_options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aegis/resource.rb', line 24 def create_or_update_action(name, , ) action = nil if action = find_action_by_name(name) action.update() else action = Action.new(name, ) @actions << action end action end |
#find_action_by_name(name) ⇒ Object
19 20 21 22 |
# File 'lib/aegis/resource.rb', line 19 def find_action_by_name(name) name = name.to_s @actions.detect { |action| action.name == name } end |
#index_actions_by_path(aliases) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/aegis/resource.rb', line 77 def index_actions_by_path(aliases) index = {} actions.each do |action| action_paths(action, aliases).each do |path| index[path] = action end end children.each do |child| index.merge! child.index_actions_by_path(aliases) end index end |
#inspect ⇒ Object
15 16 17 |
# File 'lib/aegis/resource.rb', line 15 def inspect "Resource(#{{:name => name || 'root', :actions => actions, :children => children, :parent => parent}.inspect})" end |
#new_action_takes_object?(action_options = {}) ⇒ Boolean
90 91 92 |
# File 'lib/aegis/resource.rb', line 90 def new_action_takes_object?( = {}) collection? && [:collection] != true # && !never_takes_object end |
#new_action_takes_parent_object?(action_options = {}) ⇒ Boolean
94 95 96 |
# File 'lib/aegis/resource.rb', line 94 def new_action_takes_parent_object?( = {}) parent && parent.collection? # && !parent.never_takes_object end |
#reading_actions ⇒ Object
47 48 49 |
# File 'lib/aegis/resource.rb', line 47 def reading_actions actions.reject(&:writing) end |
#root? ⇒ Boolean
35 36 37 |
# File 'lib/aegis/resource.rb', line 35 def root? type == :root end |
#singleton? ⇒ Boolean
39 40 41 |
# File 'lib/aegis/resource.rb', line 39 def singleton? type == :singleton end |
#writing_actions ⇒ Object
51 52 53 |
# File 'lib/aegis/resource.rb', line 51 def writing_actions actions.select(&:writing) end |