Class: Picatrix::Buffy

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

Constant Summary collapse

ITEM_ACTIONS =

must be disjoint due to nature of protobuf

%w{ Edit Remove }
COL_ACTIONS =
%w{ Create Filter }
CRUFD =
%w{ Create Edit Remove Filter }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Buffy.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/picatrix/buffy.rb', line 17

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

  @representation_klasses = pacman.nodes.keys.map(&:camelize)

  @item_representations = @representation_klasses.map(&:singularize).uniq
  @col_representations = @representation_klasses.map(&:pluralize).uniq
  @resources = @item_representations + @col_representations

  @link_relations = pacman.edges.collect do |edge|
    target = edge[edge.keys.first][:target]
    link_relation = edge[edge.keys.first][:link_relation]
    if link_relation[0] != ':' && !CRUFD.map(&:downcase).include?(link_relation)
      "#{link_relation.camelize}" + "#{target.camelize}"
    end
  end.compact.uniq
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



6
7
8
# File 'lib/picatrix/buffy.rb', line 6

def app_name
  @app_name
end

Returns the value of attribute link_relations.



6
7
8
# File 'lib/picatrix/buffy.rb', line 6

def link_relations
  @link_relations
end

#representation_klassesObject

Returns the value of attribute representation_klasses.



6
7
8
# File 'lib/picatrix/buffy.rb', line 6

def representation_klasses
  @representation_klasses
end

#resourcesObject

Returns the value of attribute resources.



6
7
8
# File 'lib/picatrix/buffy.rb', line 6

def resources
  @resources
end

Instance Method Details

#slayObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/picatrix/buffy.rb', line 38

def slay
  # TODO need to make prefix setter
  @prefix = app_name[0]
  @host = "http://localhost:9292/"

  template(
    'templates/namespaces.json',
    File.join("../../generated/#{app_name}/support/namespaces.json")
  )

  template(
    'templates/app.proto',
    File.join("../../generated/#{app_name}/support/#{app_name}.proto")
  )
end