Module: SmoothOperator::Core::ClassMethods

Defined in:
lib/smooth_operator/core.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointObject



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_passObject



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_userObject



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_nameObject



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_listObject



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_listObject



166
167
168
# File 'lib/smooth_operator/core.rb', line 166

def save_attr_white_list
  @save_attr_white_list ||= []
end

#table_nameObject



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, options = {})
  defaults = []
  defaults << "smooth_operator.attributes.#{name.underscore}.#{attribute_key_name}"
  defaults << "activerecord.attributes.#{name.underscore}.#{attribute_key_name}".to_sym
  defaults << options[:default] if options[:default]
  defaults.flatten!
  defaults << attribute_key_name.to_s.humanize
  options[:count] ||= 1
  I18n.translate(defaults.shift, options.merge(default: defaults))
end

#model_name_downcaseObject



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, nested_object_class_or_options|
    define_method(nested_object_symbol.to_s) do
      get_nested_object_variable(nested_object_symbol, nested_object_class_or_options)
    end
  end
end