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
# 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'
  @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

#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



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

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

#date_days_ago(days) ⇒ Object



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

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)


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

def development?
  @env == 'development'
end

#end_timeObject



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

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)


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

def keep_tmp?
  @keep_tmp
end

#log_fileObject



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

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

#production?Boolean

Returns:

  • (Boolean)


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

def production?
  @env == 'production'
end

#s3Object



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

def s3
  @s3_config
end

#slackObject



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

def slack
  @slack_token
end

#sshObject



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

def ssh
  @config['ssh']
end

#start_timeObject



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

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



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

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