Class: Coffer::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/coffer/definition.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDefinition

Returns a new instance of Definition.



11
12
13
# File 'lib/coffer/definition.rb', line 11

def initialize
  validate!
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



9
10
11
# File 'lib/coffer/definition.rb', line 9

def config
  @config
end

Class Method Details

.attr_field(name, default = nil) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/coffer/definition.rb', line 99

def attr_field( name, default=nil )
  @defaults ||= {}
  @defaults[name] = default

  @attr_fields ||= []
  @attr_fields << name

  instance_variable_set "@#{name}", default

  define_singleton_method(name) do |v=nil|
    unless v.nil?
      instance_variable_set "@#{name}", v
    end

    basecoin = self.ancestors[1]

    instance_variable_get("@#{name}") || basecoin.instance_variable_get(:'@defaults')[name]
  end

  define_method(name) do
    self.class.instance_variable_get "@#{name}"
  end

end

.build_configObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/coffer/definition.rb', line 77

def build_config
  return @config if @config

  @config = Configuration.new

  @config.add :rpcuser, 'cofferuser'
  @config.add :rpcpassword, 'cofferpass'
  @config.add :server, '1'
  @config.add :rpcallowip, '127.0.0.1'
  @config.add :listen, '1'
  @config.add :port, '4444' #Coffer::Registry.port

  # now custom fields
  if @config_fields
    fields.each do |f|
      @config.add f[0], f[1]
    end
  end

  @config
end

.call_rpc(*args) ⇒ Object

TODO: parse output and return



50
51
52
53
54
55
56
# File 'lib/coffer/definition.rb', line 50

def call_rpc(*args)
  pid = Process.spawn(
    executable_path, *args
  )

  Process.wait pid
end

.config_field(key, value) ⇒ Object



36
37
38
39
# File 'lib/coffer/definition.rb', line 36

def config_field( key, value )
  @config_fields ||= []
  @config_fields << [key,value]
end

.executable_pathObject



41
42
43
# File 'lib/coffer/definition.rb', line 41

def executable_path
  "/opt/coffer/bin/#{ wallet_executable }"
end

.installed?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/coffer/definition.rb', line 45

def installed?
  File.exists? executable_path
end

.nameObject



31
32
33
34
# File 'lib/coffer/definition.rb', line 31

def name
  name = ActiveSupport::Inflector.demodulize(self)
  name = ActiveSupport::Inflector.underscore(name)
end

.startObject

TODO: figure out if launch was successful



59
60
61
62
63
64
65
66
# File 'lib/coffer/definition.rb', line 59

def start
  pid = Process.spawn(
         executable_path, "-daemon",
         :out => '/dev/null', :err => '/dev/null')

  # Detach the spawned process
  Process.detach pid
end

.stopObject



68
69
70
71
72
73
74
75
# File 'lib/coffer/definition.rb', line 68

def stop
  pid = Process.spawn(
         executable_path, "stop",
         :out => '/dev/null', :err => '/dev/null')

  # Detach the spawned process
  Process.detach pid
end

Instance Method Details

#nameObject



25
26
27
# File 'lib/coffer/definition.rb', line 25

def name
  self.class.name
end

#requirementsObject



21
22
23
# File 'lib/coffer/definition.rb', line 21

def requirements
  @@requirements
end

#validate!Object



15
16
17
18
19
# File 'lib/coffer/definition.rb', line 15

def validate!
  raise "Git repo required!" if @@git_repo.nil?
  raise "wallet_executable required!" if @@wallet_executable.nil?
  raise "directory required!" if @@directory.nil?
end