Class: Eh::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/eh/settings.rb

Defined Under Namespace

Classes: Proxy, Repository

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Settings

Returns a new instance of Settings.



53
54
55
56
57
# File 'lib/eh/settings.rb', line 53

def initialize(file)
  @file = file
  @data = JSON.parse(File.read(file))
  @data["proxies"] ||= []
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



2
3
4
# File 'lib/eh/settings.rb', line 2

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



2
3
4
# File 'lib/eh/settings.rb', line 2

def file
  @file
end

Class Method Details

.currentObject



73
74
75
# File 'lib/eh/settings.rb', line 73

def self.current
  Thread.current[:eh_settings]
end

.current=(value) ⇒ Object



69
70
71
# File 'lib/eh/settings.rb', line 69

def self.current=(value)
  Thread.current[:eh_settings] = value
end

.load(file) ⇒ Object



59
60
61
# File 'lib/eh/settings.rb', line 59

def self.load(file)
  Eh::Settings.new(file)
end

Instance Method Details

#console_source_dirObject



125
126
127
# File 'lib/eh/settings.rb', line 125

def console_source_dir
  File.join(repository.dir, "src", "rails", "console")
end

#db_backups_dirObject



162
163
164
# File 'lib/eh/settings.rb', line 162

def db_backups_dir
  File.expand_path("~/backups")
end

#default_stageObject



49
50
51
# File 'lib/eh/settings.rb', line 49

def default_stage
  @data["default_stage"] || "development"
end

#deployment_dirObject



129
130
131
# File 'lib/eh/settings.rb', line 129

def deployment_dir
  File.join(repository.dir, "src", "deployment")
end

#deployment_management_filesObject



154
155
156
# File 'lib/eh/settings.rb', line 154

def deployment_management_files
  [File.join(deployment_dir, "management", "launcher.rb")]
end

#go_processors_src_dirObject



121
122
123
# File 'lib/eh/settings.rb', line 121

def go_processors_src_dir
  File.join(repository.dir, "src", "go", "src", "github.com", "cme-eventhub")
end

#go_release_dirObject



113
114
115
# File 'lib/eh/settings.rb', line 113

def go_release_dir
  releases_dir("go")
end

#package_tmp_dirObject



146
147
148
# File 'lib/eh/settings.rb', line 146

def package_tmp_dir
  "./tmp"
end

#processor_template_repository_urlObject



142
143
144
# File 'lib/eh/settings.rb', line 142

def processor_template_repository_url
  "https://github.com/thomis/eventhub-processor-template.git"
end

#proxiesObject



92
93
94
95
96
97
98
99
# File 'lib/eh/settings.rb', line 92

def proxies
  if data["proxies"]
    proxies = data["proxies"].map do |json|
      Eh::Settings::Proxy.new(json)
    end
  end
  proxies || []
end

#rails_release_dirObject



105
106
107
# File 'lib/eh/settings.rb', line 105

def rails_release_dir
  releases_dir("rails")
end

#rails_src_dirObject



133
134
135
136
# File 'lib/eh/settings.rb', line 133

def rails_src_dir
  # appears 2 times. What is correct?
  File.join(repository.dir, "src", "rails", "console")
end

#releases_dir(*extra_paths) ⇒ Object



101
102
103
# File 'lib/eh/settings.rb', line 101

def releases_dir(*extra_paths)
  File.join(repository.dir, "releases", *extra_paths)
end

#repositoriesObject



83
84
85
86
87
88
89
90
# File 'lib/eh/settings.rb', line 83

def repositories
  if data["repositories"]
    repos = data["repositories"].map do |json|
      Eh::Settings::Repository.new(json)
    end
  end
  repos || []
end

#repositoryObject



77
78
79
80
81
# File 'lib/eh/settings.rb', line 77

def repository
  repositories&.find do |repository|
    repository.current?
  end
end

#ruby_processors_src_dirObject



117
118
119
# File 'lib/eh/settings.rb', line 117

def ruby_processors_src_dir
  File.join(repository.dir, "src", "ruby")
end

#ruby_release_dirObject



109
110
111
# File 'lib/eh/settings.rb', line 109

def ruby_release_dir
  releases_dir("ruby")
end

#source_config_dirObject



138
139
140
# File 'lib/eh/settings.rb', line 138

def source_config_dir
  File.join(repository.dir, "config")
end

#stages_dirObject



158
159
160
# File 'lib/eh/settings.rb', line 158

def stages_dir
  File.join(repository.dir, "config", "stages")
end

#template_tmp_dirObject



150
151
152
# File 'lib/eh/settings.rb', line 150

def template_tmp_dir
  "/tmp/eventhub-processor-template/"
end

#writeObject



63
64
65
66
67
# File 'lib/eh/settings.rb', line 63

def write
  File.open(file, "w") do |f|
    f.write(data.to_json)
  end
end