class Blueprinter::Generators::BlueprintGenerator
Attributes
options[RW]
Public Instance Methods
create_blueprint()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 44 def create_blueprint template "blueprint.rb", File.join(path, "#{file_path}_blueprint.rb") end
ensure_blueprint_dir()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 40 def ensure_blueprint_dir FileUtils.mkdir_p(path) unless File.directory?(path) end
Private Instance Methods
association_blueprint(association_name)
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 108 def association_blueprint(association_name) ", blueprint: #{association_class(association_name)}" end
association_class(association_name)
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 112 def association_class(association_name) introspected_name = if introspected_associations[association_name].respond_to?(:klass) introspected_associations[association_name].klass.to_s else nil end "#{introspected_name || association_name.camelcase}Blueprint" end
associations()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 95 def associations as = if options["detect_associations"] Array.new(options["associations"]).concat(introspected_associations.keys) else options["associations"] end as.reject {|f| f.blank? }.uniq end
fields()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 62 def fields fs = if options["detect_fields"] Array.new(options["fields"]).concat(introspected_fields) else options["fields"] end fs.reject {|f| f.blank? }.uniq end
formatted_fields()
click to toggle source
split at wrap_at chars, two indentations
# File lib/generators/blueprinter/blueprint_generator.rb, line 76 def formatted_fields two_indents = indent * 2 fields_string = fields.reduce([]) do |memo, f| if !memo.last.nil? now = "#{memo.last} :#{f}," if now.length > options["wrap_at"].to_i memo << ":#{f}," else memo[memo.length - 1] = now end else memo << " :#{f}," end memo end.join("\n#{two_indents}") fields_string[0,fields_string.length - 1] end
identifier_symbol()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 56 def identifier_symbol if options['identifier'] options['identifier'] == "identifier" ? :id : options['identifier'] end end
indent()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 121 def indent user_intended = {two: " ", four: " ", tab:"\t"}[options["indentation"].intern] user_intended.nil? ? " " : user_intended end
introspected_associations()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 104 def introspected_associations class_name.constantize.reflections end
introspected_fields()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 71 def introspected_fields class_name.constantize.columns_hash.keys end
path()
click to toggle source
# File lib/generators/blueprinter/blueprint_generator.rb, line 52 def path options["blueprints_dir"] end