class Picatrix::Prototyper
Constants
- PROTOBUF_FIXTURES
Attributes
destination_stack[RW]
options[RW]
resources[RW]
Public Class Methods
new(nodes, options = {}, app_name = "app")
click to toggle source
# File lib/picatrix/prototyper.rb, line 19 def initialize(nodes, options = {}, app_name = "app") # thor related @options = options @destination_stack = [self.class.source_root] @resources = nodes.keys.select {|n| n if n.pluralize == n} resources.each do |resource| @resource_name = resource.camelize @fields = @resource_name.singularize. constantize.fields.inject({}) do |memo, field| field_value = if PROTOBUF_FIXTURES[field.type_class] # TODO this is too general need some way to signal # primary key which is addressable if field.name.to_s.include?("id") "id = #{PROTOBUF_FIXTURES[field.type_class]}" else PROTOBUF_FIXTURES[field.type_class] end elsif field.type_class.to_s.demodulize == "Controls" "#{field.type_class}.new(minimal_controls_for(item_id))" else # TODO recursively gen these relations "[#{field.type_class}.new(params = {})]" end memo[field.name] = field_value memo end template( 'templates/type.rb', File.join("../../generated/#{app_name}/resources/#{resource}.rb") ) end end