Module: SmoothOperator::Core::ClassMethods
- Defined in:
- lib/smooth_operator/core.rb
Instance Attribute Summary collapse
- #endpoint ⇒ Object
- #endpoint_pass ⇒ Object
- #endpoint_user ⇒ Object
- #model_name ⇒ Object
- #save_attr_black_list ⇒ Object
- #save_attr_white_list ⇒ Object
- #table_name ⇒ Object
Instance Method Summary collapse
- #human_attribute_name(attribute_key_name, options = {}) ⇒ Object
- #model_name_downcase ⇒ Object
- #nested_objects_classes(hash) ⇒ Object
Instance Attribute Details
#endpoint ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/smooth_operator/core.rb', line 134 def endpoint if defined?(@endpoint) @endpoint else @endpoint = superclass_responds_to?(:endpoint) ? superclass.endpoint : ENV["API_ENDPOINT"] end end |
#endpoint_pass ⇒ Object
152 153 154 155 156 157 158 |
# File 'lib/smooth_operator/core.rb', line 152 def endpoint_pass if defined?(@endpoint_pass) @endpoint_pass else @endpoint_pass = superclass_responds_to?(:endpoint_pass) ? superclass.endpoint_pass : ENV["API_PASS"] end end |
#endpoint_user ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/smooth_operator/core.rb', line 143 def endpoint_user if defined?(@endpoint_user) @endpoint_user else @endpoint_user = superclass_responds_to?(:endpoint_user) ? superclass.endpoint_user : ENV["API_USER"] end end |
#model_name ⇒ Object
171 172 173 |
# File 'lib/smooth_operator/core.rb', line 171 def model_name @model_name ||= name.split('::').last.underscore.capitalize end |
#save_attr_black_list ⇒ Object
161 162 163 |
# File 'lib/smooth_operator/core.rb', line 161 def save_attr_black_list @save_attr_black_list ||= [:id, :created_at, :updated_at, :errors] end |
#save_attr_white_list ⇒ Object
166 167 168 |
# File 'lib/smooth_operator/core.rb', line 166 def save_attr_white_list @save_attr_white_list ||= [] end |
#table_name ⇒ Object
180 181 182 |
# File 'lib/smooth_operator/core.rb', line 180 def table_name @table_name ||= model_name_downcase.to_s.pluralize end |
Instance Method Details
#human_attribute_name(attribute_key_name, options = {}) ⇒ Object
184 185 186 187 188 189 190 191 192 193 |
# File 'lib/smooth_operator/core.rb', line 184 def human_attribute_name(attribute_key_name, = {}) defaults = [] defaults << "smooth_operator.attributes.#{name.underscore}.#{attribute_key_name}" defaults << "activerecord.attributes.#{name.underscore}.#{attribute_key_name}".to_sym defaults << [:default] if [:default] defaults.flatten! defaults << attribute_key_name.to_s.humanize [:count] ||= 1 I18n.translate(defaults.shift, .merge(default: defaults)) end |
#model_name_downcase ⇒ Object
175 176 177 |
# File 'lib/smooth_operator/core.rb', line 175 def model_name_downcase model_name.downcase end |
#nested_objects_classes(hash) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/smooth_operator/core.rb', line 125 def nested_objects_classes(hash) hash.each do |nested_object_symbol, | define_method(nested_object_symbol.to_s) do get_nested_object_variable(nested_object_symbol, ) end end end |