Class: Picatrix::Jenny

Inherits:
Object
  • Object
show all
Includes:
Thor::Actions, Thor::Base
Defined in:
lib/picatrix/jenny.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pacman, options = {}, app_name = "app") ⇒ Jenny

Returns a new instance of Jenny.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/picatrix/jenny.rb', line 15

def initialize(pacman, options = {}, app_name = "app")
  # thor related
  @options = options
  @destination_stack = [self.class.source_root]

  @nodes = pacman.nodes
  @edges = pacman.edges

  @app_name = app_name
  @rels = LinkRelationIndex.new(@edges).masoned
  # TODO
  @meta = {}

  if File.exist?(
      namespaces_path = "generated/#{app_name}/support/namespaces.json"
  ) #TODO this should be coming in from graph instead
    @namespaces = JSON.parse(
      File.read(
        namespaces_path
      )
    )
    @prefix = "#{@namespaces["@namespaces"].keys.first}:"
  else
    puts "no generated/#{app_name}/support/namespaces.json file"
    @namespaces = {}
    @prefix = ""
  end
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



9
10
11
# File 'lib/picatrix/jenny.rb', line 9

def app_name
  @app_name
end

#destination_stackObject

Returns the value of attribute destination_stack.



9
10
11
# File 'lib/picatrix/jenny.rb', line 9

def destination_stack
  @destination_stack
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/picatrix/jenny.rb', line 9

def options
  @options
end

#relsObject

Returns the value of attribute rels.



9
10
11
# File 'lib/picatrix/jenny.rb', line 9

def rels
  @rels
end

#root_pathObject

Returns the value of attribute root_path.



9
10
11
# File 'lib/picatrix/jenny.rb', line 9

def root_path
  @root_path
end

#routesObject

Returns the value of attribute routes.



9
10
11
# File 'lib/picatrix/jenny.rb', line 9

def routes
  @routes
end

Instance Method Details

#generate_sinatra_of(app_name) ⇒ Object



75
76
77
78
79
80
# File 'lib/picatrix/jenny.rb', line 75

def generate_sinatra_of(app_name)
  template(
    'templates/app.rb',
    File.join("../../generated/#{app_name}/#{app_name}.rb")
  )
end

#just_do_itObject



44
45
46
47
# File 'lib/picatrix/jenny.rb', line 44

def just_do_it
  setup_framework_for(app_name)
  generate_sinatra_of(app_name)
end

#setup_framework_for(app_name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/picatrix/jenny.rb', line 49

def setup_framework_for(app_name)
  template(
    'templates/mason.rb',
    File.join("../../generated/#{app_name}/support/mason.rb")
  )

  Protoc.to_ruby(app_name)

  begin
    jenny_path = File.dirname( __FILE__ )
    $:.unshift File.expand_path( File.join( jenny_path, "..", "..", "generated" ) )
    $:.unshift File.expand_path( File.join( jenny_path, "..", "..", "generated", "#{app_name}" ) )
    $:.unshift File.expand_path( File.join( jenny_path, "..", "..", "generated", "#{app_name}", "support" ) )

    require_all("./generated/#{app_name}/**/*.rb")
  rescue LoadError => e
    puts "#{e}"
  end

  @control_templates = Cruddy.new(@edges).controls
  @resources = Prototyper.new(@nodes, {}, app_name).resources
  @routes = Routes.new(@edges, @control_templates)
  # make this available to the app scope
  @root_path = @routes.root_path
end