Module: Pulp::Common::Lifecycle::ClassMethods
- Defined in:
- lib/pulp/common/lifecycle.rb
Instance Method Summary collapse
-
#has_collection(options = {}) ⇒ Object
optional features.
- #has_create ⇒ Object
- #has_crud(options = {}) ⇒ Object
- #has_delete ⇒ Object
- #has_get ⇒ Object
- #has_update ⇒ Object
- #locked_fields ⇒ Object
- #pulp_action(action_name, options = {}) ⇒ Object
- #pulp_deferred_field(field, options = {}) ⇒ Object
-
#pulp_deferred_fields(*fields) ⇒ Object
Declare many deffered fields at once.
-
#pulp_field(field, options = {}) ⇒ Object
Allows for dynamically declaring fields that will come from Pulp.
-
#pulp_fields(*fields) ⇒ Object
Declare many fields at once.
-
#pulp_locked_field(field, options = {}) ⇒ Object
declare a field that is locked.
-
#pulp_locked_fields(*fields) ⇒ Object
Declare many locked fields at once.
-
#pulp_special_field(field, options = {}) ⇒ Object
special fields are locked and registered as being special.
-
#pulp_special_fields(*fields) ⇒ Object
Declare multiple special fields at once.
- #pulp_update_action(action_name, options) ⇒ Object
- #record_fields ⇒ Object
- #special_fields ⇒ Object
Instance Method Details
#has_collection(options = {}) ⇒ Object
optional features
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pulp/common/lifecycle.rb', line 83 def has_collection(={}) instance_eval %{ def all base_get('').collect {|e| self.new(e) } end} [:all_filters] && [:all_filters].each do |filter| instance_eval %{ def find_by_#{filter}(f) base_get('',nil,{ :#{filter} => f }).collect {|e| self.new(e) } end} end end |
#has_create ⇒ Object
109 110 111 |
# File 'lib/pulp/common/lifecycle.rb', line 109 def has_create include Pulp::Common::Lifecycle::Create end |
#has_crud(options = {}) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/pulp/common/lifecycle.rb', line 97 def has_crud(={}) has_collection([:collection]||{}) has_create has_get has_update has_delete end |
#has_delete ⇒ Object
105 106 107 |
# File 'lib/pulp/common/lifecycle.rb', line 105 def has_delete include Pulp::Common::Lifecycle::Delete end |
#has_get ⇒ Object
113 114 115 |
# File 'lib/pulp/common/lifecycle.rb', line 113 def has_get include Pulp::Common::Lifecycle::Get end |
#has_update ⇒ Object
117 118 119 |
# File 'lib/pulp/common/lifecycle.rb', line 117 def has_update include Pulp::Common::Lifecycle::Update end |
#locked_fields ⇒ Object
160 161 162 |
# File 'lib/pulp/common/lifecycle.rb', line 160 def locked_fields @locked_fields ||= [] end |
#pulp_action(action_name, options = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/pulp/common/lifecycle.rb', line 121 def pulp_action(action_name, ={}) [:method] ||= :post [:params] = true if [:params].nil? # default is true slash = ([:append_slash].nil? || [:append_slash]) ? '/' : '' if [:returns] module_eval %{ def #{action_name}(#{"params#{"={}" if [:params] == :optional}" if [:params]}) #{[:returns]}.new(self.class.base_#{([:parse] == false) ? 'unparsed_' : '' }#{[:method]}('#{action_name}#{slash}',self.id,#{[:params] ? 'params' : 'nil' })) end} else module_eval %{ def #{action_name}(#{"params#{"={}" if [:params] == :optional}" if [:params]}) self.class.base_#{([:parse] == false) ? 'unparsed_' : '' }#{[:method]}('#{action_name}#{slash}',self.id,#{[:params] ? 'params' : 'nil' }) end} end if [:task_list] module_eval %{ def #{action_name}_tasks self.class.base_get('#{action_name}#{slash}',self.id).collect{|p| Pulp::Task.new(p) } end} end end |
#pulp_deferred_field(field, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pulp/common/lifecycle.rb', line 43 def pulp_deferred_field(field,={}) if [:array] module_eval("def #{field}() self.class.plain_get(fields['#{field}']).collect{|p| #{[:array]}.new(p) }; end") elsif [:returns] == :plain module_eval("def #{field}() self.class.plain_base.connection[fields['#{field}'].sub(/^\\/pulp\\/api\\//,'')].get; end") elsif [:returns] module_eval("def #{field}() (res = self.class.plain_get(fields['#{field}'])).empty? ? nil : #{[:returns]}.new(res); end") else module_eval("def #{field}() self.class.plain_get(fields['#{field}']); end") end module_eval("def #{field}_link() fields['#{field}']; end") end |
#pulp_deferred_fields(*fields) ⇒ Object
Declare many deffered fields at once.
57 58 59 |
# File 'lib/pulp/common/lifecycle.rb', line 57 def pulp_deferred_fields(*fields) [*fields].each {|field| pulp_deferred_field(field) } end |
#pulp_field(field, options = {}) ⇒ Object
Allows for dynamically declaring fields that will come from Pulp.
29 30 31 32 33 34 35 36 |
# File 'lib/pulp/common/lifecycle.rb', line 29 def pulp_field(field,={}) locked_fields << field if [:locked] module_eval("def #{field}() user_fields['#{field}'] || fields['#{field}']; end") module_eval("def #{field}=(val) user_fields['#{field}'] = val; end") unless [:locked] record_fields[field] = end |
#pulp_fields(*fields) ⇒ Object
Declare many fields at once.
39 40 41 |
# File 'lib/pulp/common/lifecycle.rb', line 39 def pulp_fields(*fields) fields.to_a.each {|field| pulp_field(field) } end |
#pulp_locked_field(field, options = {}) ⇒ Object
declare a field that is locked
62 63 64 |
# File 'lib/pulp/common/lifecycle.rb', line 62 def pulp_locked_field(field,={}) pulp_field field, .merge(:locked => true) end |
#pulp_locked_fields(*fields) ⇒ Object
Declare many locked fields at once.
67 68 69 |
# File 'lib/pulp/common/lifecycle.rb', line 67 def pulp_locked_fields(*fields) [*fields].each {|field| pulp_locked_field(field) } end |
#pulp_special_field(field, options = {}) ⇒ Object
special fields are locked and registered as being special
72 73 74 75 |
# File 'lib/pulp/common/lifecycle.rb', line 72 def pulp_special_field(field,={}) pulp_locked_field(field,) special_fields << field end |
#pulp_special_fields(*fields) ⇒ Object
Declare multiple special fields at once
78 79 80 |
# File 'lib/pulp/common/lifecycle.rb', line 78 def pulp_special_fields(*fields) [*fields].each{|f| pulp_special_field(f) } end |
#pulp_update_action(action_name, options) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/pulp/common/lifecycle.rb', line 145 def pulp_update_action(action_name,) module_eval %{ def update_#{action_name}(#{[*[:params]].join(', ')}) self.class.base_put('',self.id,{ #{[*[:params]].collect{|p| ":#{p} => #{p}" }.join(', ')} }) end} end |
#record_fields ⇒ Object
156 157 158 |
# File 'lib/pulp/common/lifecycle.rb', line 156 def record_fields @record_fields ||= {} end |
#special_fields ⇒ Object
152 153 154 |
# File 'lib/pulp/common/lifecycle.rb', line 152 def special_fields @special_fields ||= [] end |