Class: Redata::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/redata/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = nil) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
11
12
13
14
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
# File 'lib/redata/config.rb', line 5

def initialize(argv=nil)
	# params
	@argv = parse_params argv
	if !@argv[:dir]
		@root = Pathname.new(Dir.pwd)
	elsif Pathname.new(@argv[:dir]).absolute?
		@root = Pathname.new(@argv[:dir])
	else
		@root = Pathname.new(Dir.pwd).join @argv[:dir]
	end
	@env = @argv[:env] || 'development'
    @identify = @argv[:identify]
	@is_forced = @argv[:force]
	@is_ssh = @argv[:ssh]
	@is_append = @argv[:append_mode]
	@locals = @argv[:locals]
	@params = @argv[:params]

	# config file
    unless @root.join('config', 'redata.yml').exist?
      puts "Redata loading error: config/redata.yml not found" 
      return nil
    end
	@config = YAML.load(ERB.new(File.read(@root.join 'config', 'redata.yml')).result(binding))
	@s3_config = @config['s3']
	@s3_config['bucket'] += "-dev" unless @env == 'production'
	@s3_config['region'] = 'ap-northeast-1'
	@s3_config['host'] = "https://s3-#{@s3_config['region']}.amazonaws.com/#{@s3_config['bucket']}"
	Aws.config.update({
		region: @s3_config['region'],
		credentials: Aws::Credentials.new(@s3_config['aws_access_key_id'], @s3_config['aws_secret_access_key'])
	})
	@tz_local = Timezone[@config['timezone']]
	@slack_token = @config['slack_bot']
	@keep_tmp = @config['keep_tmp']
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



3
4
5
# File 'lib/redata/config.rb', line 3

def env
  @env
end

#identifyObject

Returns the value of attribute identify.



3
4
5
# File 'lib/redata/config.rb', line 3

def identify
  @identify
end

#is_appendObject

Returns the value of attribute is_append.



3
4
5
# File 'lib/redata/config.rb', line 3

def is_append
  @is_append
end

#is_forcedObject

Returns the value of attribute is_forced.



3
4
5
# File 'lib/redata/config.rb', line 3

def is_forced
  @is_forced
end

#is_sshObject

Returns the value of attribute is_ssh.



3
4
5
# File 'lib/redata/config.rb', line 3

def is_ssh
  @is_ssh
end

#localsObject

Returns the value of attribute locals.



3
4
5
# File 'lib/redata/config.rb', line 3

def locals
  @locals
end

#paramsObject

Returns the value of attribute params.



3
4
5
# File 'lib/redata/config.rb', line 3

def params
  @params
end

#rootObject

Returns the value of attribute root.



3
4
5
# File 'lib/redata/config.rb', line 3

def root
  @root
end

Instance Method Details

#current_timeObject



88
89
90
# File 'lib/redata/config.rb', line 88

def current_time
	@tz_local.utc_to_local(Time.now.utc).strftime('%Y-%m-%d %H:%M:%S')
end

#date_days_ago(days) ⇒ Object



96
97
98
# File 'lib/redata/config.rb', line 96

def date_days_ago(days)
	@tz_local.utc_to_local(Time.now.utc-days*24*3600).strftime('%Y-%m-%d')
end

#development?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/redata/config.rb', line 42

def development?
	@env == 'development'
end

#end_timeObject



67
68
69
70
71
72
73
74
# File 'lib/redata/config.rb', line 67

def end_time
	return @locals[:end_time] if @locals[:end_time]
	if @is_append
		@tz_local.utc_to_local(Time.now.utc-@config['append_interval']['end_time']*24*3600).strftime('%Y-%m-%d')
	else
		@tz_local.utc_to_local(Time.now.utc-@config['create_interval']['end_time']*24*3600).strftime('%Y-%m-%d')
	end
end

#keep_tmp?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/redata/config.rb', line 50

def keep_tmp?
	@keep_tmp
end

#log_fileObject



54
55
56
# File 'lib/redata/config.rb', line 54

def log_file
	@root.join 'log', "#{@env}_redata.log"
end

#production?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/redata/config.rb', line 46

def production?
	@env == 'production'
end

#s3Object



80
81
82
# File 'lib/redata/config.rb', line 80

def s3
	@s3_config
end

#slackObject



84
85
86
# File 'lib/redata/config.rb', line 84

def slack
	@slack_token
end

#sshObject



76
77
78
# File 'lib/redata/config.rb', line 76

def ssh
	@config['ssh']
end

#start_timeObject



58
59
60
61
62
63
64
65
# File 'lib/redata/config.rb', line 58

def start_time
	return @locals[:start_time] if @locals[:start_time]
	if @is_append
		@tz_local.utc_to_local(Time.now.utc-@config['append_interval']['start_time']*24*3600).strftime('%Y-%m-%d')
	else
		@config['create_interval']['start_time']
	end
end

#todayObject



92
93
94
# File 'lib/redata/config.rb', line 92

def today
	@tz_local.utc_to_local(Time.now.utc).strftime('%Y-%m-%d')
end