Class: Prick::State

Inherits:
Object
  • Object
show all
Defined in:
lib/prick/state.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#databaseObject

Name of database



34
35
36
# File 'lib/prick/state.rb', line 34

def database
  @database
end

#database_versionObject (readonly)

Version from prick.versions.version. Retrieved dynamically. TODO FIXME: Where is conn?



25
26
27
# File 'lib/prick/state.rb', line 25

def database_version
  @database_version
end

#environmentObject

Run-time environment. Can be :production, :development, or :test



31
32
33
# File 'lib/prick/state.rb', line 31

def environment
  @environment
end

#nameObject

Used as an identifier and the default database and username



13
14
15
# File 'lib/prick/state.rb', line 13

def name
  @name
end

#prick_versionObject

Version of prick(1)



28
29
30
# File 'lib/prick/state.rb', line 28

def prick_version
  @prick_version
end

#schema_versionObject (readonly)

Version in schema/prick/data.sql. Retrieved dynamically. TODO



22
23
24
# File 'lib/prick/state.rb', line 22

def schema_version
  @schema_version
end

#titleObject

Capitalized name of project



16
17
18
# File 'lib/prick/state.rb', line 16

def title
  @title
end

#usernameObject

Name of database user



37
38
39
# File 'lib/prick/state.rb', line 37

def username
  @username
end

#versionObject

Version in prick.yml. Can be nil



19
20
21
# File 'lib/prick/state.rb', line 19

def version
  @version
end

Class Method Details

.loadObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/prick/state.rb', line 39

def self.load
  begin
    h = YAML.load(File.read PRICK_PROJECT_PATH)
  rescue Errno::ENOENT
    raise Prick::Error, "Can't open project file: #{PRICK_PROJECT_PATH}"
  end
  state = State.new
  state.name = h["name"]
  state.title = h["title"]
  state.version = h["version"] && PrickVersion.new(h["version"])
  state.prick_version = h["prick"] && PrickVersion.new(h["prick"])

  begin
    h = YAML.load(File.read PRICK_CONTEXT_PATH)
  rescue Errno::ENOENT
    raise Prick::Error, "Can't open environment file: #{PRICK_CONTEXT_PATH}"
  end
  state.environment = h["environment"]&.to_sym
  state.database = h["database"]
  state.username = h["username"]

  # TODO Load schema version

  state
end

Instance Method Details

#dumpObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/prick/state.rb', line 95

def dump
  puts "State"
  indent {
    for method in [
        :name, :title, :prick_version, :project_version, :schema_version,
        :database_version, :environment, :database, :username]
      puts "#{method}: #{self.send method}"
    end
  }
end

#fileObject

State file



7
# File 'lib/prick/state.rb', line 7

def file() PRICK_PROJECT_PATH end

#saveObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/prick/state.rb', line 65

def save
  h = {
    "name" => name,
    "title" => title,
    "version" => version.to_s,
    "prick" => prick_version.to_s
  }
  File.write(PRICK_PROJECT_PATH, h.to_yaml)

  h = {
    "environment" => environment.to_s,
    "database" => database,
    "username" => username
  }
  File.write(PRICK_CONTEXT_PATH, h.to_yaml)

  if version
    File.write(SCHEMA_VERSION_PATH, 
        "          --\n          -- This file is auto-generated by prick(1). Please don't touch\n          --\n          delete from prick.versions;\n          insert into prick.versions (fork, major, minor, patch, pre, feature, version)\n              values (null, \#{version.major}, \#{version.minor}, \#{version.patch}, null, null, '\#{version}');\n        EOS\n    )\n  end\nend\n"

#schema_fileObject

Schema data file



10
# File 'lib/prick/state.rb', line 10

def schema_file() SCHEMA_VERSION_PATH end