Class: Picatrix::Prototyper
- Inherits:
-
Object
- Object
- Picatrix::Prototyper
- Includes:
- Thor::Actions, Thor::Base
- Defined in:
- lib/picatrix/prototyper.rb
Constant Summary collapse
- PROTOBUF_FIXTURES =
{ Protobuf::Field::Int32Field => "Faker::Number.number(6)", Protobuf::Field::StringField => "Faker::Lorem.word" }
Instance Attribute Summary collapse
-
#destination_stack ⇒ Object
Returns the value of attribute destination_stack.
-
#options ⇒ Object
Returns the value of attribute options.
-
#resources ⇒ Object
Returns the value of attribute resources.
Instance Method Summary collapse
-
#initialize(nodes, options = {}, app_name = "app") ⇒ Prototyper
constructor
A new instance of Prototyper.
Constructor Details
#initialize(nodes, options = {}, app_name = "app") ⇒ Prototyper
Returns a new instance of Prototyper.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/picatrix/prototyper.rb', line 19 def initialize(nodes, = {}, app_name = "app") # thor related @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 |
Instance Attribute Details
#destination_stack ⇒ Object
Returns the value of attribute destination_stack.
9 10 11 |
# File 'lib/picatrix/prototyper.rb', line 9 def destination_stack @destination_stack end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/picatrix/prototyper.rb', line 9 def @options end |
#resources ⇒ Object
Returns the value of attribute resources.
9 10 11 |
# File 'lib/picatrix/prototyper.rb', line 9 def resources @resources end |