Class: FourEyes::ControllerResource

Inherits:
Object
  • Object
show all
Defined in:
lib/four_eyes/controller_resource.rb

Direct Known Subclasses

InheritedResource

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller, *args) ⇒ ControllerResource

Returns a new instance of ControllerResource.



109
110
111
112
113
114
# File 'lib/four_eyes/controller_resource.rb', line 109

def initialize(controller, *args)
  @controller = controller
  @params = controller.params
  @options = args.extract_options!
  @name = args.first
end

Class Method Details

.add_maker_create_function(controller_class, method, *args) ⇒ Object

Define the dynamic maker_create function This handles the storing of the action and it’s meta data to the four_eyes_actions table with the status of ‘Initiated’



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/four_eyes/controller_resource.rb', line 8

def self.add_maker_create_function(controller_class, method, *args)
  options = args.extract_options!
  controller_class.send :define_method, method do |*args|
    "#{method} #{args}"
    resource_class_name = args[0]
    resource_id = args[1]
    object_class_name = args[2]
    data = args[3]

    action = FourEyes::Action.new(resource_class_name: resource_class_name,
                                  maker_resource_id: resource_id,
                                  resource_class_name: resource_class_name,
                                  action_type: 'action_create',
                                  object_resource_class_name: object_class_name,
                                  status: 'Initiated',
                                  data: data)
    if action.save!
      true
    else
      # TODO dondeng - Better to raise an exception here
      false
    end
  end
end

.add_maker_delete_function(controller_class, method, *args) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/four_eyes/controller_resource.rb', line 58

def self.add_maker_delete_function(controller_class, method, *args)
  options = args.extract_options!
  controller_class.send  :define_method, method do |*args|
    resource_class_name = args[0]
    resource_id = args[1]
    object_class_name = args[2]
    object_resource_id = args[3]
    data = args[4]

    action = FourEyes::Action.new(resource_class_name: resource_class_name,
                                  maker_resource_id: resource_id,
                                  action_type: 'action_delete',
                                  object_resource_class_name: object_class_name,
                                  object_resource_id: object_resource_id,
                                  status: 'Initiated',
                                  data: data)
    if action.save
      true
    else
      # TODO - dondeng - Better to raise an exception here
      false
    end
  end
end

.add_maker_generic_function(controller_class, method, *args) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/four_eyes/controller_resource.rb', line 83

def self.add_maker_generic_function(controller_class, method, *args)
  options = args.extract_options!
  controller_class.send  :define_method, method do |*args|
    resource_class_name = args[0]
    resource_id = args[1]
    object_class_name = args[2]
    object_resource_id = args[3]
    action = args[4]
    data = args[5]

    action = FourEyes::Action.new(resource_class_name: resource_class_name,
                                  maker_resource_id: resource_id,
                                  action_type: action,
                                  object_resource_class_name: object_class_name,
                                  object_resource_id: object_resource_id,
                                  status: 'Initiated',
                                  data: data)
    if action.save
      true
    else
      # TODO - dondeng - Better to raise an exception here
      false
    end
  end
end

.add_maker_update_function(controller_class, method, *args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/four_eyes/controller_resource.rb', line 33

def self.add_maker_update_function(controller_class, method, *args)
  options = args.extract_options!
  controller_class.send :define_method, method do |*args|
    resource_class_name = args[0]
    resource_id = args[1]
    object_class_name = args[2]
    object_resource_id = args[3]
    data = args[4]

    action = FourEyes::Action.new(resource_class_name: resource_class_name,
                                  maker_resource_id: resource_id,
                                  action_type: 'action_update',
                                  object_resource_class_name: object_class_name,
                                  object_resource_id: object_resource_id,
                                  status: 'Initiated',
                                  data: data)
    if action.save
      true
    else
      # TODO - dondeng - Better to raise an exception here
      false
    end
  end
end