class Jsonapi::TypeGenerator
Public Instance Methods
copy_serializable_file()
click to toggle source
TODO(beauby): Implement generator-level whitelisting. TODO(beauby): Implement versioning.
# File lib/generators/jsonapi/type/type_generator.rb, line 8 def copy_serializable_file template 'type.rb.erb', File.join('app/resources', class_path, "#{serializable_file_name}.rb") end
Private Instance Methods
attr_names()
click to toggle source
# File lib/generators/jsonapi/type/type_generator.rb, line 33 def attr_names attrs = model_klass.new.attribute_names - ['id'] fk_attrs = model_klass.reflect_on_all_associations(:belongs_to) .map(&:foreign_key) attrs - fk_attrs end
has_many_rel_names()
click to toggle source
# File lib/generators/jsonapi/type/type_generator.rb, line 45 def has_many_rel_names model_klass.reflect_on_all_associations(:has_many).map(&:name) end
has_one_rel_names()
click to toggle source
# File lib/generators/jsonapi/type/type_generator.rb, line 40 def has_one_rel_names model_klass.reflect_on_all_associations(:has_one).map(&:name) + model_klass.reflect_on_all_associations(:belongs_to).map(&:name) end
model_klass()
click to toggle source
# File lib/generators/jsonapi/type/type_generator.rb, line 24 def model_klass # TODO(beauby): Ensure the model class exists. class_name.safe_constantize end
serializable_class_name()
click to toggle source
# File lib/generators/jsonapi/type/type_generator.rb, line 20 def serializable_class_name (class_path + [serializable_file_name]).map!(&:camelize).join("::") end
serializable_file_name()
click to toggle source
# File lib/generators/jsonapi/type/type_generator.rb, line 16 def serializable_file_name "#{file_name}_resource" end
type()
click to toggle source
# File lib/generators/jsonapi/type/type_generator.rb, line 29 def type model_klass.model_name.plural end