Class: LogicalConstruct::NodeClient

Inherits:
Object
  • Object
show all
Defined in:
lib/logical-construct/node-client.rb

Defined Under Namespace

Classes: ManifestBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNodeClient

Returns a new instance of NodeClient.



26
27
28
29
# File 'lib/logical-construct/node-client.rb', line 26

def initialize
  @plan_archives = []
  @silent = false
end

Instance Attribute Details

#node_urlObject

Returns the value of attribute node_url.



31
32
33
# File 'lib/logical-construct/node-client.rb', line 31

def node_url
  @node_url
end

#plan_archivesObject

Returns the value of attribute plan_archives.



31
32
33
# File 'lib/logical-construct/node-client.rb', line 31

def plan_archives
  @plan_archives
end

#serverObject

Returns the value of attribute server.



31
32
33
# File 'lib/logical-construct/node-client.rb', line 31

def server
  @server
end

#silentObject

Returns the value of attribute silent.



31
32
33
# File 'lib/logical-construct/node-client.rb', line 31

def silent
  @silent
end

Instance Method Details

#deliver_manifestObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/logical-construct/node-client.rb', line 62

def deliver_manifest
  report "Delivering manifest"
  messages = []
  server.putting do |root|
    messages = []
    needs = page_labeled("Server Manifest", root)

    builder = ManifestBuilder.new(needs)

    plan_archives.each do |archive|
      messages << "Adding #{archive}"
      builder.add_plan(archive)
    end
  end
  report messages
end

#deliver_plansObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/logical-construct/node-client.rb', line 79

def deliver_plans
  loop do
    needs = []
    server.getting do |root|
      needs = []
      unresolved = page_labeled("Unresolved Plans", root)

      unresolved[:lc, "plans"].as_list.each do |need|
        needs << [need[:lc, "name"], need[:lc, "contents"]]
      end
    end
    if needs.empty?
      report "Target needs fulfilled"
      break
    end

    report "Delivering plan archives"
    needs.each do |need|
      name, path = *need
      plan = plan_archives.find do |plan|
        File.basename(plan) == name
      end

      next if plan.nil?

      File::open(plan, "r") do |file|
        report " Delivering #{name}"
        server.put_file(path, "application/x-gtar-compressed", file) #sorta like a ukulele
      end
    end
  end
end

#page_labeled(label, focus) ⇒ Object



55
56
57
58
59
60
# File 'lib/logical-construct/node-client.rb', line 55

def page_labeled(label, focus)
  concept = focus.all(:skos, "hasTopConcept").find do |concept|
    concept.all(:skos, "prefLabel").include?(label) or concept.all(:skos, "altLabel").include?(label)
  end
  concept.first(:foaf, "page")
end

#report(item) ⇒ Object



39
40
41
# File 'lib/logical-construct/node-client.rb', line 39

def report(item)
  puts item unless silent
end

#resolved?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/logical-construct/node-client.rb', line 51

def resolved?
  state.downcase == "resolved"
end

#stateObject



43
44
45
46
47
48
49
# File 'lib/logical-construct/node-client.rb', line 43

def state
  state = nil
  server.getting do |root|
    state = page_labeled("Current Status", root)[:lc, "node-state"]
  end
  state
end