Class: ActiveGroonga::Schema
- Inherits:
-
Object
- Object
- ActiveGroonga::Schema
- Defined in:
- lib/active_groonga/schema.rb
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) define {|@schema| ... }
- - (Object) dump(output = nil)
-
- (Schema) initialize(options = {})
constructor
A new instance of Schema.
Constructor Details
- (Schema) initialize(options = {})
Returns a new instance of Schema
37 38 39 40 41 42 |
# File 'lib/active_groonga/schema.rb', line 37 def initialize(={}) @options = ( || {}).dup @version = @options.delete(:version) context = @options.delete(:context) || Base.context @schema = Groonga::Schema.new(:context => context) end |
Class Method Details
+ (Object) define(options = {}, &block)
21 22 23 |
# File 'lib/active_groonga/schema.rb', line 21 def define(={}, &block) new().define(&block) end |
+ (Object) dump(options = {})
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
- (Object) define {|@schema| ... }
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 |
- (Object) dump(output = nil)
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 |