Class: ActiveGroonga::Schema
- Inherits:
-
Object
- Object
- ActiveGroonga::Schema
- Defined in:
- lib/active_groonga/schema.rb
Class Method Summary collapse
Instance Method Summary collapse
- #define {|@schema| ... } ⇒ Object
- #dump(output = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Schema
constructor
A new instance of Schema.
Constructor Details
#initialize(options = {}) ⇒ Schema
Returns a new instance of Schema.
37 38 39 40 41 42 |
# File 'lib/active_groonga/schema.rb', line 37 def initialize(={}) = ( || {}).dup @version = .delete(:version) context = .delete(:context) || Base.context @schema = Groonga::Schema.new(:context => context) end |
Class Method Details
.define(options = {}, &block) ⇒ Object
21 22 23 |
# File 'lib/active_groonga/schema.rb', line 21 def define(={}, &block) new().define(&block) end |
.dump(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_groonga/schema.rb', line 25 def dump(={}) ||= {} if .is_a?(Hash) = .dup output = .delete(:output) else output, = , {} end new().dump(output) end |
Instance Method Details
#define {|@schema| ... } ⇒ Object
44 45 46 47 48 |
# File 'lib/active_groonga/schema.rb', line 44 def define(&block) yield(@schema) @schema.define update_version if @version end |
#dump(output = nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_groonga/schema.rb', line 50 def dump(output=nil) dumped_schema = @schema.dump return nil if dumped_schema.nil? return_string = false if output.nil? output = StringIO.new return_string = true end version = @version || management_table.current_version output << "ActiveGroonga::Schema.define(:version => #{version}) do |schema|\n" output << " schema.instance_eval do\n" dumped_schema.each_line do |line| if /^\s*$/ =~ line output << line else output << " #{line}" end end output << " end\n" output << "end\n" if return_string output.string else output end end |